Page 1 of 1

autopopulate same table

PostPosted: Thu Aug 09, 2012 3:44 am
by tomtom8
Hello!
I have to fill out a form, if a field is already present in the database can automatically fill in other fields. Basically I have a table with field WorkOrder (cod_odl) and fields such as, (name) (address), (tel) etc. .. If completing a new Form I insert the field (cod_cli) and this is already in the db, I can automatically populate the remaining fields as: (name) (address), (tel), etc..
Thank you.

Michele

Re: autopopulate same table

PostPosted: Thu Aug 09, 2012 11:23 am
by shannah
If you wanted to populate this in the form (i.e. before submitting it) then you'll need to use some javascript and ajax. If I were you, I'd create an action that returns JSON with the data you need. Then create a Javascript function that responds to the onchange handler for your field that calls your ajax action and uses the data to populate the other fields.

Re: autopopulate same table

PostPosted: Tue Nov 20, 2012 9:35 am
by mermentau
shannah wrote:If you wanted to populate this in the form (i.e. before submitting it) then you'll need to use some javascript and ajax. If I were you, I'd create an action that returns JSON with the data you need. Then create a Javascript function that responds to the onchange handler for your field that calls your ajax action and uses the data to populate the other fields.
I really need this functionality. Any clues where I could find more detailed documentation?

Re: autopopulate same table

PostPosted: Tue Nov 20, 2012 10:53 am
by shannah
I don't have an example of this exactly. But the steps would roughly be:

1. Create a custom action that takes, as input, the field that is selected, and outputs the the data that you intend to use to prepopulate the other fields.
2. Create a Javascript function that uses AJAX to call your custom action, and populate the fields.
3. Attach a change handler to the field that should trigger this, and call your javascript function.

Re: autopopulate same table

PostPosted: Wed Nov 28, 2012 7:21 pm
by mermentau
Sorry shannah I missed your response here. I didn't realize we had to manually subscribe to the thread. Anyway I was able to solve the problem with JavaScript. Not exactly as you described, but it's working.