PDA

View Full Version : Good approach to load a fairly complicated form from one lookup



cshamis
7 Jul 2010, 5:31 PM
Hi all,

I've got a fairly complicated customer order form:
Full name, (First, MI, Last)
preferred and alternate shipping address,
phones (fax, mobile, main),
email... etc...
Now, assuming that all my customer information is stored in a DB, what I'd like to be able to do is this:
If you type in the phone number, the rest of the fields populate.
If you type in the name, the rest of the fields populate.
If you type in the street address, the rest of the fields populate.
You get the idea. In cases where there's non-unique results, I want to use an iPhone-Maps style popup that asks for clarification if there are ambiguities...

Now I already have a datastore up and working that will populate combobox for the name set to fire after 4 characters... and I'm getting the record id for the customer based on the selection of the combobox... the question is, how do I use that "id" to load all the other fields on the form?

Do I just write a new action or something for the on.select method of the combobox that goes out, hits the database, retreives a JSON string with all the fields, and then busts it open and sticks the proper values into the proper fields? That's easy enough.... however.

I'd like to be able to use just about any field on the form for the "lookup" that would (or could) return the record id for the customer, and then have a more generic function that takes the "id" as an argument and then performs the lookup and then populates all the fields automatically...

I'm thinking: if I match the column names of the customer record to each of the Ext "id" fields on the panel, then I could just go through the JSON and stick the values into each field on the form using somekind of Ext.lookup to get the id of the Ext field (which is the same as the column name in the db) and set the value.

Am I being Na´ve? Is there much more to it than that?

-C.

babsjr77
8 Jul 2010, 10:58 AM
Once you load the data you can use formpanel.getForm().loadRecord or formpanel.getForm().setValues to set the field values. No need to do the lookup of the fields yourself.