iFormBuilder JavaScript Tips & Tricks
There may be a situation where the select widget is defaulting to the first option in the list when using the Dynamic Value of {-1}. If you would like your select widget to default to blank or no options selected please follow the steps below.
STEP 1. Add a Select Widget on your form. We will be naming it my_select_element.
STEP 2. Assign an option list to the Select element.
STEP 3. Add a Text Element to the very bottom of your form. We named it select_clear. This is important that it is at the very bottom of the form.
STEP 4. In the Dynamic Value of the Select Element, add in the following:
if(select_clear=="yes"){my_select_element=-1}
STEP 5. In the Dynamic Value of the Text Element, add in the following:
"yes"
To hide this element (which we would recommend), add in the following to the Condition Value:
false
This function will allow the select widget to always default to no options selected when you first open the form.
Comments
4 comments
Why is it important that the hidden field be at the bottom of the form?
Would this work with pick list elements as well?
Hi Mike, this should apply to pick list widget as well.
@ Ben, you don't need to hide it, but makes for a cleaner user experience.
Another way is to simply write this as the Dynamic Value for the select:
{my_select=-1}
I'm not sure why it works, but it reliably works on android and apple. David at IForms Support says this approach is fine.
Same idea applies to other types of element. For a text control, it would be:
{my_text = ""}
Please sign in to leave a comment.