How can i reset the dropdown selections?
can i clear the dropdowns items?
How can i reset the dropdown selections?
can i clear the dropdowns items?
Hi,
you can set dropdown selections by setting options property on a dropdown. You can also clear the options by setting it an an empty array.
You can find full API here:
Hi Giedrius,
I want to reset the drop down placeholder to default value when a button is clicked. I used code as shown here.
export function sortbutton_click(event) {
$w("#stateselectbutton").placeholder = "Select State:";
$w("#adtypeselectbutton").placeholder = "Select Type:";
$w("#typeselectbutton").placeholder = "Select Category:";
}
But unfortunately its not resting the place holder. Am I doing anything wrong?
Hi Nithin,
You can reset the value of the dropdown elements to the placeholder text.
export function sortbutton_click(event) {
$w("#stateselectbutton").value = "Select State:";
$w("#adtypeselectbutton").value = "Select Type:";
$w("#typeselectbutton").value = "Select Category:"; }
You can refer to this website on how to reset dropdown elements.
https://www.vorbly.com/Vorbly-Code/WIX-CODE-RESET-FORM-WITH-BUTTON
Good luck!
Cheers,
Ben
Hi guys!
Note that the two methods are different with different purposes.
The “.placeholder” method changes the default writing in the input field, you can even say it changes the title of the field.
The “.value” method changes the value of the user’s input. Lets say that I have an input field for a phone number. The ‘placeholder’ is - Phone Number;
While the value will be my input would be: +123 45 - 6789 - 012.
Other than that, #Nithin, your code seems fine.
Make sure that you use the correct selector name (aka Component ID; aka $w(‘#yourComponent’) ) and that the event of ‘sortbutton_click’ exists in the button’s properties.
Hope it helps!
Doron.
@doron-alkalay Issues I have found with clear buttons
I was finally able to make this work. I have 5 dropdowns that all pull their information from one dataset. I added a button and used the below code to return all values to the placeholder text, which on my page is “Select”. It took me a long time to figure this out as I am a first time coder. Several of the examples I tried just would not work. Be sure to set the button properties to “onClick()”
export function button3_click ( event , $w ) {
// This function was added from the Properties & Events panel.
// Add your code for this event here:
$w ( “#dropdown1” ). selectedIndex = null ;
$w ( “#dropdown2” ). selectedIndex = null
$w ( “#dropdown3” ). selectedIndex = null ;
$w ( “#dropdown4” ). selectedIndex = null ;
$w ( “#dropdown5” ). selectedIndex = null ;
}
Amazing solution… … You saved my life buddy. A truck full of thanks.