PDA

View Full Version : Setting errorReader in Ext.Form



JTM
2 May 2007, 1:38 PM
When using using a custom 'errorReader' for an Ext.form, the same JsonReader is also used for the 'success = true' cases; thus causing an error because the expected 'data' property is not available. What is the proper way to assign a custom reader for submit failures, while using the default values for success cases? Possible bug?

Thanks!

My code:


new Ext.form.Form({
errorReader: new Ext.data.JsonReader({
successProperty: 'success',
root: 'errors'
}, [
{mapping: 'code', name: 'id'},
{mapping: 'message', name: 'msg'}
]),
},
url: 'my.url'
});

And the Ext code in question:



handleResponse : function(response){
if(this.form.errorReader){
var rs = this.form.errorReader.read(response);
var errors = [];
if(rs.records){
for(var i = 0, len = rs.records.length; i < len; i++) {
var r = rs.records[i];
errors[i] = r.data;
}
}
if(errors.length < 1){
errors = null;
}
return {
success : rs.success,
errors : errors
};
}
return Ext.decode(response.responseText);
}

JTM
3 May 2007, 7:54 AM
Of course, Ext again proves to be smarter than I am. The solution to my problem, as pointed out in various other forum posts, was to extend the default form Action's handleResponse method to account for my specific situation. Worked like a charm.