PDA

View Full Version : FormPanel record object



mohaaron
9 Jun 2009, 1:57 PM
I am trying to figure out how to get access to the record object of the FormPanel. I use the following code to load the FormPanel from a JsonStore on load. I want to be able to pass the record.id value to the params collection when I submit the form. I can't find any way to do this.

Here is the FormPanel being loaded from the JsonStore.


var jsonStore = new Ext.data.JsonStore({
url: '/Bug/GetBugs',
totalProperty: 'totalRows',
root: 'rows',
id: 'PKId',
fields: [
'PKId',
to many fields to list...
],
listeners: {
load: function(store, records, options) {
try {
var record = store.getAt(0);
var form = Ext.getCmp('mainForm');
if (form)
form.getForm().loadRecord(record);
} catch(err) {
console.log(err);
}
},
loadexception: function(store, options, response, e) {
console.log(e);
}
}
});


Here is the submit function on the FormPanel.


buttons: [{
text: 'Save',
handler: function() {
Ext.getCmp('mainForm').getForm().submit({
url: '/Bugs/Edit', // The REST based url that the data will be saved to.
method: 'POST',
params: { id: '10' },
waitTitle: 'Processing...',
waitMsg: 'Please wait...'
});
}
}]


I would like to pass something like selectedRecord.id in place of the value '10' which is some made of value for testing. Is it possible to get access to the record which is bound to the form?

nomack84
9 Jun 2009, 5:53 PM
I you take a look at the source code, you'll see that a form have no record defined inside. When you do some load record or something that using a record, what the method do is take the record data property, and them iterate throw all that propertys, and make setValues to each form's field.

It's clear enouth?

Sorry if there are any mistake in my languaje.

mohaaron
10 Jun 2009, 10:42 AM
OK, I think what I take from your answer is that I don't have access to the record that has been loaded into the form. So what I am going to do is create a new variable to store the currently selected record when it's loaded from the store. I can then use the currentRecord variable in my submit event.

Thanks for helping me think about this!