PDA

View Full Version : Bug in markInvalid / findField cause field to mark as invalid



Wolfgang
31 Jul 2007, 11:27 AM
Hello,

i think there is a bug in handling findField in markInvalid (Ext 1.1R1):
Starting from line 23723 in ext-debug.js


findField : function(id){
var field = this.items.get(id);
if(!field){
this.items.each(function(f){
if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
field = f;
return false;
}
});
}
return field || null;
},


markInvalid : function(errors){
if(errors instanceof Array){
for(var i = 0, len = errors.length; i < len; i++){
var fieldError = errors[i];
var f = this.findField(fieldError.id);
if(f){
f.markInvalid(fieldError.msg);
}
}
}else{
var field, id;
for(id in errors){
if(typeof errors[id] != 'function' && (field = this.findField(id))){
field.markInvalid(errors[id]);
}
}
}
return this;
},


In particular here:


var f = this.findField(fieldError.id);

findField returns a field of the current form, even when fieldError.id is undefined, but errors is set.
So what happens is, that a field of the form gets marked invalid, without having set this in errors.


Regards

Wolfgang

jack.slocum
31 Jul 2007, 12:10 PM
Can I ask what you are doing? The id is not optional.

Wolfgang
31 Jul 2007, 1:09 PM
I try to errorcheck the response of a form.
The challange is not to get the response back from the server, but to make sure the response itself is a valid response (valid JSON or XML).

Searching through the forum, i found i have to setup an errorReader:


frmBuchung = new Ext.form.Form({
labelAlign: 'top',
url: 'respUpdateBuchung',
method: 'POST',
hiddenId: '',
hiddenId_fz: '',
//baseParams:{action:'set'}
errorReader: errorReader
});

Because i have not found anything about how to setup an errorReader, i started debugging the code and came up with this, to understand how the errorReader should work and to simulate the answer of the backend.



// error reader for form
var errorReader = Object();
errorReader.read = function(response) {
var rs = Object();
rs.records = Array();
// response that cause one field to be marked invalid
rs.records.push( {data :{'name': 'adatum'}});
// valid responses that work
//rs.records.push( {data :{'id': 'adatum', 'msg': 'fehler adatum'}});
//rs.records.push( {data :{'id': 'fahrzeug', 'msg': response.responseText}});
return rs;
};

It seems that the record must be an object 'data' with at least the property 'id'.
In my frst try during debugging, i started with the property 'name' and ran into the issue i mentioned. If this is correct, i would suggest, that findField in general should only return a field if there is a match.

Regards

Wolfgang