Buy Now
Sign in

Retrieve dynamic dropdown's option from database

webbusteruk , October 04 2020, 17:34
webbusteruk 186
October 04 2020, 17:34 #394188
We have a form with a few dynamic dropdown fields. Upon selecting "Dropdown 1" field, "Dropodown 2" field is reloaded with new options.
We now want to edit a row on the database, so we retrieve it into a form. We can load the Selected values into "Dropdown 1" from the database row. However, as the option in "Dropdown 1" is not selected on load, "Dropdown 2" value cannot be pre-selected with value from database on load.
Hope we made the question clear! Thanks for your help in advance.
In Dropdown1, Selected value set as {var:read_data.Model.dropdown1}. Events set to Reload Dropdown2 on change.

In Dropdown2, Selected value set as {var:read_data.Model.dropdown2}.

On page load, Dropdown1 rightly has {var:read_data.Model.dropdown1} as its value.
However Dropdown2 does not have any value selected.
admin 33
October 06 2020, 03:57 #394212
in v6 the fields trigger the "change" event when they are loaded, in v7 they call the "Ready" event, I would sugget that you install v7 and give it a try on the same website!
webbusteruk 186
October 06 2020, 13:07 #394220
We are using CCv6. The event is triggered on load, first Dropdown correctly shows the selected value automatically and reloads the second Dropdown with the correct corresponding options.
It's the second Dropdown that we cannot make it automatically set to its selected value from database, even though {var:read_data.Model.dropdown2} is put under "Selected values".
Elitakey 370
January 17 2021, 11:16 #395688
If somebody looking for this - you should add the read_action for the old data value on reload.
So, the steps would look like this:
1) read old data value in dropdown with read data>first matching record where id:{data:id}
2) put the value in the field data with data builder: Type:Data; Name: field_name; Value: {var:read_data_name.Model.field_name};
3) Read data for Dynamic dropdown as it was before;
4) view file field with custom code as it was before.
All of this is in Standalone action that is called by reload