Hi,
I have used Dynamic dropdown Example like example.
I have a dropdown list that get data from db. In read data(event auto) i get 2 fields to retrieve (id and name). Es. id=1, name= Milano.
The name is the value that i have in my dropdown.
Now i want to fill a text box selecting from db a value where id = myid (example. id = 1)
How can i do?
Regards
Daniele
I have used Dynamic dropdown Example like example.
I have a dropdown list that get data from db. In read data(event auto) i get 2 fields to retrieve (id and name). Es. id=1, name= Milano.
The name is the value that i have in my dropdown.
Now i want to fill a text box selecting from db a value where id = myid (example. id = 1)
How can i do?
Regards
Daniele
Hi Daniele,
Usually the simplest way to do this is to use a second Read Data action in the form On Submit event using the submitted drop-down selection to identify the record to read.
Bob
Usually the simplest way to do this is to use a second Read Data action in the form On Submit event using the submitted drop-down selection to identify the record to read.
Bob
Ho Bob,
thanks but i have to populate the text box dinamically, without click on button (so i immage that i cannot use a "On Submit Event") . I image to pass the selected "id" [that i get from "Read data action" in event "auto", called from Dropdown component (AutoComplete event)] to an event that contain a "Read Data Action" that get the value from a table and populate the text box. Is it ok? If yes, how can i do it? How can i pass the selected "id" and In which event i have to insert "Read Data Action" to get the value to populate the textbox?
Thanks very much Bob
regards
thanks but i have to populate the text box dinamically, without click on button (so i immage that i cannot use a "On Submit Event") . I image to pass the selected "id" [that i get from "Read data action" in event "auto", called from Dropdown component (AutoComplete event)] to an event that contain a "Read Data Action" that get the value from a table and populate the text box. Is it ok? If yes, how can i do it? How can i pass the selected "id" and In which event i have to insert "Read Data Action" to get the value to populate the textbox?
Thanks very much Bob
regards
So just to check I have things right.
You want to populate a dropdown with data from a database.
When the user selects an option on the dropdown, you want to replace the data in a textbox with new data from the database matching the row.
I spent an hour on this just for fun and learning so get ready. Change all the names of things to whatever you need for your form.
You have a dropdown, let's call it "dropdown".
Under "events", you want On: change, Actions: reload, Identifier: text_field
I will assume you already correctly set up the read data actions in your load event to dynamically populate the dropdown.
You have a text field, let's call it "text_field".
Under "advanced", you want Reload event: reload_text_field
You have a database table called xx_my_data, with three fields: id, name, flavour.
Under the "Setup" tab at the bottom of the page, create a new event called "reload_text_field".
You then want a Read Data action, with your table selected, and call the model "model".
* Where conditions: model.id:{data:dropdown}
* Fields to retrieve: model.flavour
* Select type: first matching record
Then you need a PHP action (under "Logic"). Replace "action_name" with the name of the read data action, the text in the black Name box. It should probably be "read_data5" or something along those lines.
$this->data("text_field", $this->get("action_name.model.flavour", ""), true);
Lastly, you need a Custom code action, with:
{view:text_field_view_name} where text_field_view_name is the Name: in the black label of the field.
*drops mic*
You want to populate a dropdown with data from a database.
When the user selects an option on the dropdown, you want to replace the data in a textbox with new data from the database matching the row.
I spent an hour on this just for fun and learning so get ready. Change all the names of things to whatever you need for your form.
You have a dropdown, let's call it "dropdown".
Under "events", you want On: change, Actions: reload, Identifier: text_field
I will assume you already correctly set up the read data actions in your load event to dynamically populate the dropdown.
You have a text field, let's call it "text_field".
Under "advanced", you want Reload event: reload_text_field
You have a database table called xx_my_data, with three fields: id, name, flavour.
Under the "Setup" tab at the bottom of the page, create a new event called "reload_text_field".
You then want a Read Data action, with your table selected, and call the model "model".
* Where conditions: model.id:{data:dropdown}
* Fields to retrieve: model.flavour
* Select type: first matching record
Then you need a PHP action (under "Logic"). Replace "action_name" with the name of the read data action, the text in the black Name box. It should probably be "read_data5" or something along those lines.
$this->data("text_field", $this->get("action_name.model.flavour", ""), true);
Lastly, you need a Custom code action, with:
{view:text_field_view_name} where text_field_view_name is the Name: in the black label of the field.
*drops mic*
Hi,
thanks for your clear explanation but it does not work, in the sense that when I select a dropdown value, my textbox disappears.Anyway, I have a doubt about that said:
I have a dropdown (name:comune) and a text box (name:provincia)
In Dropdown, Under Advanced, i have autoComplete event called: "auto" and under Events i have On: change, Actions: reload, Identifier: provincia (text box's name)
Under the "Setup" tab at the bottom of the page, i have event called "auto".
1)i have a Read Data action (name:read_data4), with my table selected, and the model is "Data".
* Where conditions: Data.nomeComune/LIKE:{data:comune}%
* Fields to retrieve:
Data.idProvincia
Data.nomeComune
* Select type: Return an array of key/value pairs, two field must be provided.
2) Then a have a custom code with:{var/jsonen:read_data4}
I followed your procedure but maybe the problem is here.
When you say:
Under the "Setup" tab at the bottom of the page, create a new event called "reload_text_field".
You then want a Read Data action, with your table selected, and call the model "model".
* Where conditions: model.id:{data:dropdown} --> I think that the problem is here, because i have to refer to dropdown id, which is : Data.idProvincia...what should I put in place of "date: dropdown"?
* Fields to retrieve: model.flavour
* Select type: first matching record
Thanks very much.
Regards
Daniele
So you have an event called auto, which is what populates your dropdown. And you also have a SECOND event, called reload_text_field right?
And you should put nothing in place of data:dropdown, data:dropdown refers to the VALUE that gets sent and not the label, and you have it set up correctly in that regard
And you should put nothing in place of data:dropdown, data:dropdown refers to the VALUE that gets sent and not the label, and you have it set up correctly in that regard
Hi,
yes, i have 2 events, the first to populate the dropdown, and the secondo to populate the text box.
How does the event understand that in the "WHERE conditions" it should use the idProvincia ?
Consider that the key / value pairs (Data.idProvincia / Data.nomeComune) is recovered in the dropdown.
Regards
Daniele
yes, i have 2 events, the first to populate the dropdown, and the secondo to populate the text box.
How does the event understand that in the "WHERE conditions" it should use the idProvincia ?
Consider that the key / value pairs (Data.idProvincia / Data.nomeComune) is recovered in the dropdown.
Regards
Daniele
{data:dropdown} gets the key.
Just take a backup of your form and upload it here using the file upload button.
Just take a backup of your form and upload it here using the file upload button.
Ok, thank you![file=10364]test_dynamic_04_Apr_2018_09_37_08.cf6bak[/file]
i have updated my form.
thank you so much!
Regards
i have updated my form.
thank you so much!
Regards
In the custom code, you should have {view:name_of_the_view} not {view:name_of_the_field}. The name_of_the_view is the black label, so it's probably field_text3
Sorry..but which view? I'm sorry for the stupid question:(
Under Setup->reload_text_field->Custom Code, where you currently have {view:provincia}
Instead of that you need to use the label in the black for the field. Like in the screenshot here. So it should be {view:field_text3}
Instead of that you need to use the label in the black for the field. Like in the screenshot here. So it should be {view:field_text3}
Uauh, great!! Thank you so much! i hope that this code can help other people.
Thanks
Regards
Daniele
Thanks
Regards
Daniele
Just worked it out, you CAN nest var calls in the shortcode. So instead of needing the PHP action to do $this->data("...", "...", true), you can just put this in your Custom Code block
{data.set:reload_field$(var:read_data5.model.field)}
{view:field_text6}
{data.set:reload_field$(var:read_data5.model.field)}
{view:field_text6}
This topic is locked and no more replies can be posted.
