Forums

Set value of text fields automatically on selection of dynamic dropdown

sem 22 Feb, 2021
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 {var:Manager.name} 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 {var:Model.email} 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.

mark

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 {var:ManagerDetails.email}

Still nothing is displayed.
Max_admin 24 Feb, 2021
Answer
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!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
sem 25 Feb, 2021
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 {var:Model.id} and then match this in the Where condition for the second read action to be id = {data:dropdown_17}

Look right?

mark
sem 25 Feb, 2021
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 Model.id = {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.

Array
(
[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.


mark
czuczumcz 12 Mar, 2021
Hi,
@sem You found a solution to the problem?

i have the same situation,

in text fields on placeholder is {var:model.data) but value is empty.

any idea?
sem 15 Apr, 2021
Hi - no solution I'm afraid - hopefully Max will provide an answer. Max??

mark
You need to login to be able to post a reply.