Expandable box not working

Ji,
I, trying to implement a collapsing/expanding container box with some user inputs in it similar to what is described here: https://www.wix.com/code/home/example/Collapsing-Form

Only difference, I’m using a switch instead of checkbox.
However, NOTHING HAPPENS WHEN I TOGGLE SWITCH.
Here’s the code I’m using:

export function switch1_onChange(event) {
if ($w(‘#switch1’).checked ){
$w(‘#box1’).expand();
console.log(‘test’);
}
else
$w(‘#box1’).collapse();
}

Please help me with why I cant get this working??

Hi,
Can you please send us the site URL and the name of the page to which the code was added? Moreover, have you checked the value of $w(’ #switch1 ').checked ? I would make sure that it gets the correct value using console log.

Tal.

Hi Tal,
Thanks for your response.
Site url: www.moneyplanned.com
Page: www.moneyplanned.com/add-goal-vehicle (Requires login)
I have currently disabled the code since it was not working, but I can enable it again if required.
Also, Im not sure about the console log you are talking about.
if ($w(’ #switch1 ‘).checked ){
$w(’ #box1 ').expand();
console.log(‘test’);
}
I have included a console.log here but there is no output. So im not sure if that condition is being verified.
Should I share the editor link?
Thanks

Hi,
I checked the documentation and there’s no an onChange event for a switch toggle . I think that you can use the onClick event instead and check whether the switch toggle is checked or not.

Good luck,
Tal.

Hi,
Thanks for your solution Tal, will try and let you know :smiley:

Hi Tal, Thanks for your input. Got it working smoothly :smiley: