PDA

View Full Version : Populating form field with data from second datasource based on first



catmd2b
24 Sep 2008, 6:36 AM
I have a grid that loads data from ds just fine and dandy. What I need to do, is when the user clicks on the row, I need to send a variable back to PHP and query the db to return the result. I have this done via a listener and have ds2 load when user selects a row. But the second datastore form population isn't working. I can't really add the ds2 record to the first because they come from separate tables that do not have the same schema. I've been looking at this code, searching the forums, and going through the learning center/faqs for the past three hours. If someone could just tell me why I would be extremely thankful. Thank you!

Note: Firebug console: The ds2 does load. Now I need to access that data in the form. Should I do a drill-down for the form? ds2.sfein.value?

Condor
24 Sep 2008, 6:42 AM
I would recommend loading the second store first and then combine the data from the 2 records and load the form with that, e.g.


rowselect: function(sm, row, rec) {
var xyz = rec.get("FEIN");
ds2.load({
params: {fei: xyz},
callback: function(records, options, success) {
if (success) {
var data = Ext.apply(Ext.apply({}, rec.data), records[0].data);
Ext.getCmp("company-form").getForm().setValues(data);
}
}
});
}

catmd2b
24 Sep 2008, 6:45 AM
Thanks for your prompt reply Condor. I'm going to try your code, but before I do, a quick question. Would I not need to get the record of the first ds in order to apply it to the second? The second is dependent upon a value retrieved from the first. Then again, I haven't tried it, so I will take a looksie right now.

Thank you again!

catmd2b
24 Sep 2008, 6:49 AM
Hi,

Condor, thanks for your suggestion, but it doesn't work. I'm using an Oracle db and it throws errors about missing the variable retrieved from the clicked ds record. However, I'm going to see if I can tweak it to make it work. Thanks for your help. :)

catmd2b
24 Sep 2008, 7:07 AM
Alrighty then, I've identified and fixed the aforementioned error. Now, for something new. The console throws the error : Ext.getCmp("company-form").getForm().loadData(data); is not a function, so I tried Ext.getCmp("company-form").getForm().load(data); and in the Firebug console, it correctly lists the corresponding data for mainframe.php and the records for the other table. However, the form is not populated at all. Do I need to call a FormPanel.load(data)?

All help is appreciated. Thank you. :)

Condor
24 Sep 2008, 7:09 AM
Me bad... It should be setValues() and not loadData().

catmd2b
24 Sep 2008, 7:16 AM
Condor, you are a wonderful person! It works in Firefox, but in IE it gives the error records[0] is undefined. I do have a single record that does not have a correlating relationship between tables. I'll see what I can do about that. Thank you SO much!