JavaScript Tips and Tricks
Clearing Selected Values in various widgets
This section shows how to clear any data that was filled out previously in a form by using dynamic value with IF statements.
Let's say we have 2 elements on a form such as an "Element" (can be any of the elements listed below) and a Select Element with yes and no in the Option List. You can clear the "Element" to blank if the user selects "Yes" as their choice.
In these next few examples, I will be using a select element to show when you select yes on the "Select Yes to Clear:" element the value in the "Element" box will become blank.
Text
Dynamic Value:
if(select_data_column_name == 0){" "}
Number
Dynamic Value:
if(select_data_column_name == 0){0}
Pick List
Dynamic Value:
if(select_data_column_name == 0){-1}
Text Area
Dynamic Valueif(select_data_column_name == 0){" "}
*You must include a space in between the quotesToggle
Dynamic Value:if(select_data_column_name == 0){0}
Select
Dynamic Value:if(select_data_column_name == 0){-1}
If you are trying to clear a select element with another select element you must have use this:
if(select_data_column_name==-1 || select_data_column_name==null) {select_data_column_name}
else if(select_data_column_name==0) {-1} else {-2}
Range
Dynamic Value: if(select_data_column_name == 0){0}
if(select_data_column_name == 0){" "}
*You must include a space in between the quotesAssignTo
Dynamic Value if(select_data_column_name == 0){" "}
*You must include a space in between the quotes*PLEASE NOTE: You cannot clear Date, Time, Date-Time elements. You can set them to the current date by having
Date()
in the Dynamic Value.Similarly, if you don't have a Select element, simply use:
data_column_name =
" "
or data_column_name
= 0 depending on the element type.
Comments
3 comments
How are Date, Time, Date-Time fields cleared?
How can you clear values of elements based on a multi-select element (all these examples are based on a select element)?
It would be great if you could work on a solution which doesn't cache values from previous records. This is clearly a bug which hasn't been addressed. The recommendations above are a complex work around. This issue has cause a huge amount of issues with our data collection.
Please sign in to leave a comment.