Creating an if else statement based on a DatePicker Value

I have a date picker for users to select a date and a dropdown input for them to select time. I want to be able to change the available times based on the date value selected.

For example, on Halloween I will only offer them 3 time selections instead of the usual 9.

Thanks in advance!

Hi,

At first when you pick a date from the date picker, it returns a date and a time, so in your case you have to modify that value to be only a date and here is a cool way to do that :

const options = {
    day: "numeric",
    month: "short",
    year: "numeric"
};
 let date = $w("#datePicker").value.toLocaleDateString("en-US",options);
  console.log(date); // value will look like this => Sep 22, 2018

Then, for the dropdown options, you can define them by code inside the if statement using $w(“#dropdown”).options . For more information - Read This

And your code should look something like this :

export function datePicker_change(event) {
 const options = {
    day: "numeric",
    month: "short",
    year: "numeric"
};
 let date = $w("#datePicker").value.toLocaleDateString("en-US",options);
 if( date === "Sep 22, 2018"){
 
    $w("#dropdown").options = [
  {"label": "1", "value": "1"},
  {"label": "2", "value": "2"},
  {"label": "3", "value": "3"}
];
  }
 
}

Hope this helps!
Best,

Mustafa

This worked perfectly. Thank you!

I have two drop down menu and I want to show the comparison between them. I have created another page for comparison between selected values.

Drop down 1 selected value= A
Drop down 2 selected value = B
now A vs B is on another page , when button clicked result page should open.

Ca you please send the piece of code for this.

Thanks in Advance

@mhammouz any chance you might also know how to format the following onKeypress?
add a space every 4th digit input:
example
12345678 ----> 1234 5678
but only as the user types, so as they type it would go:
1
12
123
1234(space)
1234 5…