Zum Hauptinhalt gehen

Reset a dropdown box to have no value selected

Kommentare

11 Kommentare

  • Stefan Schweigert

    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
  • Chris Dunlop

    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
  • Alan Clack

    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 Item
    • Set Form Element Property
    • Set Property

    and then simply set current to -1 or 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 Property activities. The other options don't seem to honor the settings and Set Property works for all my situations.

    1. The first Set Property needs to set current to a blank value (e.g., ='' or leaving the field completely blank)
    2. The second Set Property needs to set value to 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
  • Ken Lyon

    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
  • Alan Clack

    👍 Thanks for the heads up. I do recall all my older code working fine by setting current alone 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 both current and value are 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
  • Ken Lyon

    @Alan Clack I don't recall the full reason behind using both current and value, 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:

    1. If value is specified but not current, it will try to find a visible item with that value. If found, the element's current property will be updated to match. If not, the value and label will be cleared.
    2. If current is specified but there is no visible item with that key, it falls back to the above logic.
    3. If current is specified and it refers to a visible item, the element's label and value properties are updated to be those of the specified item.

    In light of that, I'd say current is the more significant property and that label and value are more of a convenience to avoid needing to write $form1.state.dropDownList1.items[$form1.state.dropDownList1.current] to get at them.

    1
  • Ken Lyon

    That same logic is also performed for these elements:

    • Auto Complete
    • Check Group
    • List Box
    • Radio Group
    1
  • Alan Clack

    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
  • Ken Lyon

    Alan Clack You're welcome. I'm glad I could help!

    0
  • Brian Bolduc

    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
  • William Walker

    Using Set Form Element Property with current and value to 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

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.