Buy Now
Sign in

Set value of text fields automatically on selection of dynamic dropdown

sem , February 22 2021, 11:49
sem 90
February 22 2021, 11:49 #396023
Hi. Have looked at the demos, very useful but I'm now stuck.
I have a data table #__authorised_managers. Fields are id, name, email, jobtitle.
I have a read data action with a model name Manager. This works and I have a table list that shows all entries.
I then have a dynamic dropdown using this Model and that populates fine. It's using {} as value and text.
What I want to achieve is selecting the manager from the dropdown will auto populate text fields for name, email and job title so that they can be saved when the form is submitted. I want a free text option incase the manager isn't listed.
Putting a text field in with a value {} only returns the email field from the last row of the database. I don't think I'm doing this correctly. By default I'd like the field blank and only populated when the dropdown option is selected and updated if this is changed.
Any help appreciated.
Updated 24/02/21
Followed the connected dropdown demo.
Added standalone page manager_details with a single action RefreshManager to read the database again (model ManagerDetails) with a where condition
id = {data:id}
Then added a refresh on the text field to refresh if the dropdown changes and reload this standalone page. The value for the text field is {}
Still nothing is displayed.
admin 33
February 24 2021, 23:14 #396047
You will need to setup a reload event in the Text field settings, or if you want to load multiple values then add them in an area (container) and reload the container.
That event should be triggered when the dropdown changes.
Then you need to enable the Reload behavior for the text field too (so 2 behaviors now, events and reload) the reload behavior has a page setting, point that to a page where you will read the values you need, then in your field value value use {var:read_data_name.Model.table_field} for example!
sem 90
February 25 2021, 01:02 #396049
thanks Max. I’ll give this a go in the morning.
just to be sure, I can use {var:read_data_name:mymodel.fieldname} anywhere right? And for for me in this case (before renaming units) i'm calling {var:read_data_28.ManagerDetails.manager_email} How about in the where condition for matching the right details for the Id of the row matched by the drop down value?
So, as in the connected dropdown demo, I need 2 separate read events, one on the start page, one on a standalone page. Both read events have different model names. Both read events are essentially the same (an initial read of the table to populate the dropdown) and the second is identical except it returns the first value to match what's defined in the Where condition - so I want to only pull the row where the id = the id of the dropdown?
In fact, am I better off using the dropdown to have text {var:Model.manager_name} and value {} and then match this in the Where condition for the second read action to be id = {data:dropdown_17}
Look right?
sem 90
February 25 2021, 08:54 #396050
ok - almost there.
Dropdown works. I have a text node after the dropdown displaying {data:dropdown_17} and reloading on dropdown change so I can see the value (in this case, id). This works.
Then for the second data read, the Where is = {data:dropdown_17}. On the text input field (with reload event and action on dropdown change), I set default value and placeholder (as a check) to {var:Model.manager_email}.
This works.
Issue is, I can see the correct email showing as the placeholder. If I submit the form, the text input field is empty. No data is passed even though the default value is set as confirmed by the placeholder text. Debug on submit below. What I want to be able to see is when the dropdown is changed, the text within the input text field changes - as if the user had entered it, because in the event of the table of managers being wrong or out of date, the user must be able to manually enter the details to submit the form.
[option] => com_chronoforms7
[cont] => manager
[chronoform] => form-22feb21-0926
[gpage] => end_page
[dropdown_17] => 5
[email] =>
[__cf_token] => 2b1b249b-e9c2-4792-bbb7-85f68f389eab
If I change the text input field name from email to Model.manager_email, it creates an array and the field is still empty.
czuczumcz 1
March 12 2021, 10:49 #396130
@sem You found a solution to the problem?
i have the same situation,
in text fields on placeholder is { but value is empty.
any idea?
sem 90
April 15 2021, 14:00 #396259
Hi - no solution I'm afraid - hopefully Max will provide an answer. Max??