PDA

View Full Version : Load record in form submit



oana0211
10 Jun 2013, 6:46 AM
Hello,

I have a big problem. I want to submit a form and after submit with the response object to populate the form back with new values. I've try to use loadRecord , I see my object but my form doesn't fill with the new values. What I did wrong?


form.getForm().submit( {
clientValidation: true,
url : 'rest/dynamicForm/save',
method : 'POST',
waitMsg : 'Saving...',
headers : {
"Content-Type" : "application/json"
},
reader: {
type: 'json'
},
writer: {
type: 'json'
},
success : function(comp, action) { // When
// saving
// data
console.dir(action);
var modelFields =Ext.decode(action.response.responseText);
console.dir('model fields');
console.dir(modelFields);
var model = Ext
.define(
'aaa.model.MyModel',
{
extend : 'Ext.data.Model',
fields : modelFields
});
var record = Ext.create(model);
comp.loadRecord(record);
Ext.MessageBox
.alert('Message',
'Data has been saved');


},
failure : function(comp, action) { // when
// saving
// data
// failed
console.dir(comp);
console.dir(action);


Ext.MessageBox
.alert('Message',
'Saving data failed');

}


});

slemmon
11 Jun 2013, 9:16 PM
What does your response look like? When you apply it to the model instance and inspect the model do you see the data associated to it as expected?

oana0211
12 Jun 2013, 12:16 AM
Hello,

Yes, when I print record object I get this object


docId: "1961"
sessionToken: null
status: "INIT"
success: true
and my controls in the form has the same id.

slemmon
12 Jun 2013, 11:37 AM
When you say same ID do you mean that each form field has a 'name' config with its value corresponding to a field in the model's fields array?

oana0211
12 Jun 2013, 10:53 PM
Yes. The name of the controls are the same with my model properties.

Malro
13 Jun 2013, 3:13 AM
*edit* wrong :)

oana0211
13 Jun 2013, 3:18 AM
I have no grid, I have only an empty form that I want to populate it from a json.

Malro
13 Jun 2013, 3:24 AM
I think your record has vo values. You just create an empty model.



var modelFields = Ext.decode(action.response.responseText); var model = Ext.define('aaa.model.MyModel',{ extend : 'Ext.data.Model', fields : modelFields }); var record = Ext.create(model); //empty record!
var record2 = Ext.create(model, {
field: value,
field2: value2
});

oana0211
13 Jun 2013, 3:27 AM
Hello Marlo,

I have values in my record. In my code I printed the model record and the output is an object with the following properties:


docId: "1961"
sessionToken: null
status: "INIT"
success: true

but after loadRecord my controls still empties.

Thank you

Malro
13 Jun 2013, 3:31 AM
before loadRecord(record)

try

console.log(record.get('docId'));

oana0211
13 Jun 2013, 5:08 AM
I've try. It was indeed empty. I've try even with the following code and when I print the record.get('docId') I receive the value but my controls in my form didn't change.


var modelFields = Ext.decode(action.response.responseText);
console.dir('model fields');
console.dir(modelFields);
var record = form.getForm().getRecord();
record.set(modelFields);
console.dir(record.get('docId'));
comp.loadRecord(record);