Question:
Why is the onClick event not triggering for my date picker element in Wix Velo?
Product:
Wix studio and Wix Velo
What are you trying to achieve:
I am trying to set up a date picker that, when clicked, should enable itself and also check a travel option switch to indicate a “Round trip” selection. This functionality is part of a flight search criteria form where the return date picker’s state is dependent on the travel option switch.
What have you already tried:
I’ve implemented the following code to attach an onClick event to the return date picker:
$w.onReady(async function () {
let returnDate = $w('#datePicker2');
let travelSwitch = $w('#switch1'); // Assuming this is the ID of your travel switch
returnDate.onClick((event) => {
const datePicker = event.target; // This is the return date picker element
datePicker.enable(); // Enable the return date picker
travelSwitch.checked = true; // Check the travel switch
});
});
The onClick event should trigger when the date picker is clicked, enabling the picker and checking the travel switch. However, the event does not seem to be triggering at all.
Additional information:
The travel switch is functioning correctly, and the IDs used in the code match those set in the Wix Editor. There are no console errors, and the rest of the form functions as expected. I am unsure if there are specific considerations or restrictions for date picker elements in Wix Velo that I might be missing.