Programatically reopens a dropdown after change

Hi everyone !

So, here is my question : I would like to make a “two step” dropdown, where the first step show categories and the second step shows all interests associated to this specific category.

Here is the code I did so far, yet it’s not working because the .click() function is not recognized apparently…

// #dataset1 is connected to the dropdow list
    let interestCounter = 0
    $w('#dropdown1').onChange(() => {
        dropdownChanged()

        function dropdownChanged() {
            if (interestCounter === 0) {
            // on the first time that we click the dropdown, we filter the list of interests by the selected category value
                $w('#dataset1').setFilter(wixData.filter().eq("category", $w('#dropdown1').value)).then(() => {
                    $w('#dropdown1').click() // the part that is not working
                })
                interestCounter++
                
            } else {
                // the dropdown is programmatically clicked, and we filter the final results by the selected interest value
                $w('#resultDataset').setFilter(wixData.filter().eq("interest", $w('#dropdown1').value)).then(() => {
                    interestCounter = 0
                })
            }
        }

Thank you !

Hi Valentin.

There are a few things that should not work the way you want it.

When you look at the dataset api, it says when using the dataset, it should be in the dataset.onReady.
This is to make sure the dataset is ready before doing any eactions on it.
Otherwhise it could give errors.

Also using a function in an onChange is something you should not do.
A function is a part in the page code, otherwhise you can just put the code inside the onChange instead of calling the function.

And last:
You cannot programmatically “click” and element.
you can programmatically change the selected value, change the values, etc but “clicking” on it using code does not work.

Kind regards,
Kristof.