Forums

Dropdown + textfield autopopulate from DB

marcinwolejko 11 Oct, 2013
Hi guys,

yet again I'm asking for help.
I've been using your component for a year or so now and it's marvelous. Helped me facilitate the work in my company to such an extent that even the words cant express.

However, I've been wondering if one thing is possible. I've been searching all over and I can't seem to find a similar problem/ query.

My co-workers base their work on filling in forms with clients data.
I've set up a DB table with clients information: address, forms of payment, prices etc.

Using a DB Multirecord loader I managed to apply the client's name to the dynamic dropdown field in the form. However, I was wondering if other form fields can be automatically filled in/ populated with additional client's info, like price, form of payment on choosing the client from the dropdown. This would make it easier for my co-workers to see how they need to handle the client without having to check in a CC table with all clients I prepared for them.

What would be the best approach to achieve it?

Let me give you a quick example.

I have a form to fill in with the details of the service where we pick:
client
form of payment
service

client - picked from database jos_firmy field: client model id FIRMY
form of payment - payment to be automatically picked from jos_firmy field: payment
is it doable?
GreyHead 11 Oct, 2013
Hi marcinwolejko,

Yes it can be done but it needs to be hand-coded.

Make a copy of the form to test!

Get the Ajax JavaScript from the current page source; add it to a Load JS action on the form On Load event. Remove any Power Fields actions for the dropdown.

In the On Ajax event add code to query the database and return the data you want to use in the form. You could use a DB Record Loader but I'd probably hand-code it and return a JSON_encoded array.

Modify the OnSuccess function in the JavaScript to get the JSON encoded data and update which ever input values you need to change.

The MooTools documents for a JSON Request are here

Bob
This topic is locked and no more replies can be posted.