Reset a dropdown box to have no value selected
I often use dropdown boxes with options added with an options subworkflow from a coded value domain. When I launch my form, the dropdown initially shows no selected value. Once a value is selected, depending on what the user does in the form, I may want to reset the dropdown to its initial state with no value selected? How do I do that?
-
Hi Jostein,
You could add a 'Set Form Element Items' to the change event on one of your other elements and use an empty collection as an input to the Items property (e.g. ={}) and set Reset to true.
Also, if you have a sequence of Display Form activities and want to return to a previous form and have the values set to their original blank values, you can set the Reset property on the Display Form.
I hope this helps,
Stefan
0 -
Stefan, I'm guessing Jostein is meaning that once you select a value in the dropdown, you don't then have the option of clearing it. I'm trying to do something similar. I have a dropdown that is populated by a coded domain in the subworkflow. When you open the form, it is initally blank, and when you expand the dropdown, you see the domain values under the blank row. Once you've selected a value however, the blank row goes away, so you can't clear the dropdown.
I'm actually trying to add a value to the dropdown list of coded domains that says “-- Any Type --”. I've been banging my head trying to add it, either to the Get Coded Value Domain output, or the Get Form Element Items From Collection output, but I can't figure out how to do that. Any ideas?
Thanks,
Chris
1 -
Chris Dunlop A bit late to the party, but for anyone else having silly issues with this:
This functionality will differ slightly depending on your version of VertiGIS workflow.Older versions would allow you to use various activities such as:
Set Current Form Element ItemSet Form Element PropertySet Property
and then simply set
currentto-1or an empty string (e.g.=''or leaving the field completely blank).
This does seem to have been removed in newer versions and objects tend to need an extra step.
The most complete way I've found to remove the selection from a drop down that otherwise doesn't need to have extra unneeded values is to:Use [2]
Set Propertyactivities. The other options don't seem to honor the settings andSet Propertyworks for all my situations.- The first
Set Propertyneeds to setcurrentto a blank value (e.g., ='' or leaving the field completely blank) - The second
Set Propertyneeds to setvalueto a blank value (e.g., ='' or leaving the field completely blank)
with both of those properties set the form will be blank and is also very likely to not bypass most validity checks until the user selects a value which makes it visually and functionally reset without removing values.
1 -
I would usually recommend using Set Form Element Property because it has additional code in there to ensure the element is re-rendered. In some situations, using Set Property doesn't show any change.
The current property is the one that influences whether the component shows the placeholder text above all of the options. I see what you mean about needing to clear “value” as well, though. It does look like both need to be cleared.
1 -
👍 Thanks for the heads up. I do recall all my older code working fine by setting
currentalone via Set Form Element Property in the past, but in some environments I could not get Set Form Element Property to actually maintain the adjusted property defeating its purpose, but did do a sanity check and the above solution was the only thing I could get to work in multiple versions.
Unsure if its just a bug, but it feels like if bothcurrentandvalueare not set then the drop-down defaults to a previous value with one of them still being maintained. I didn't try every combination of objects/statuses to be cleared by all the combinations of property setting activities.. so I went with the most rudimentary that worked across all versions I have to test with and did make sure to outline my different findings. 😛
Would be interesting to see if there is any feedback on why its not changed and/or if that's intended.. 🤷♂️1 -
@Alan Clack I don't recall the full reason behind using both
currentandvalue, but I do know that we tidied things up a bit when we were migrating the Form Elements to use the newer Material UI components like VertiGIS Studio Web. It might be that we more aggressively started ensuring that those two properties were consistent.From looking at the code, it appears that when a Drop Down List is rendered initially, it will attempt the following:
- If
valueis specified but notcurrent, it will try to find a visible item with that value. If found, the element'scurrentproperty will be updated to match. If not, thevalueandlabelwill be cleared. - If
currentis specified but there is no visible item with that key, it falls back to the above logic. - If
currentis specified and it refers to a visible item, the element'slabelandvalueproperties are updated to be those of the specified item.
In light of that, I'd say
currentis the more significant property and thatlabelandvalueare more of a convenience to avoid needing to write$form1.state.dropDownList1.items[$form1.state.dropDownList1.current]to get at them.1 - If
-
That same logic is also performed for these elements:
- Auto Complete
- Check Group
- List Box
- Radio Group
1 -
Amazing followup! Those were my findings as well and all of that checks out.
I do really appreciate checking into the actual code to confirm and lay out what's required and best practices beyond that. This kind of feedback helps tremendously with reporting why somethings break over time. Thanks again. =]1 -
Alan Clack You're welcome. I'm glad I could help!
0 -
I ended up trying a bunch of stuff from the boards to reset the selected on a radioGroup item. Nothing worked for me. I ended up writing a javascript function to delete the “current”, “label”, “value” properties. That worked for me.
=function () {
delete $formFeederInfo.state.radioGroupTieDevices.current
delete $formFeederInfo.state.radioGroupTieDevices.label
delete $formFeederInfo.state.radioGroupTieDevices.value
}()0 -
Using Set Form Element Property with
currentandvalueto clear a drop down list work fine for me in Studio Web but not in Studio Mobile, this there another method to use there?0
Please sign in to leave a comment.
Comments
11 comments