Hi all!
I’ve got a drop-down where users can select values (it’s populated from a custom Data Type), or (using a separate input) can add values to the dropdown list (adds values to the custom Data Type). What I’d like to do is when a new value is added to the custom Data Type via the separate input, have the value just added be selected in the dropdown automatically.
The closest I’ve been able to come is to:
- Set the default of the dropdown to a custom state value (which is blank to start off with)
- When the new value is added to the dropdown, I set the custom state value to the new dropdown option and it populates in the dropdown just fine.
This works multiple times, as long as a value in the dropdown hasn’t been selected manually. Once a manual selection is made, the default value is no longer loaded automatically.
So I’m looking for a way to either directly set the value of the dropdown to some value, or to force a reload of the default variable from the custom state.
Here is my specific case, if it’s helpful at all:
- I’m building a character editor for a game, which will allow various calculations to be performed based on various numerical attributes of the characters (calculating possible damage, etc.). Character is the Custom Data Type.
- The user will be able to select one of their characters from the dropdown, which will bring up various fields to be edited (that will be used in other screens as input data for modeling purposes; not important here).
- I have a different input where the user can add a new character to the database, and I’d like that new character to populate the dropdown automatically. Not a huge deal, but a nice experience, and understanding how to do it (or if I simply can’t) will be good learning for me.
- When I first load the page and the default value in the custom State is null, I can keep adding new Characters and the dropdown updates correctly every time, as long as I do not manually select a value in the dropdown.
- Once I select a value in the dropdown, the dropdown value never changes again on a new character add.
Hopefully the above is enough information, but I’m happy to provide more if needed.