PDA

View Full Version : loadRecord on form



paubach
21 May 2010, 1:11 AM
Hi, I'm using the loadRecord of the BasicForm but due to some needs I have some of the fields repeated. I mean I can have 2 fields with same name and when I load the record only the first is filled. I'd need all the fields with the same name to be filled with that info

According to BasicForm.js this function works in this way:


loadRecord : function(record){
this.setValues(record.data);
return this;
},



setValues : function(values){
if(Ext.isArray(values)){ // array of objects
for(var i = 0, len = values.length; i < len; i++){
var v = values[i];
var f = this.findField(v.id);
if(f){
f.setValue(v.value);
if(this.trackResetOnLoad){
f.originalValue = f.getValue();
}
}
}
}else{ // object hash
var field, id;
for(id in values){
if(!Ext.isFunction(values[id]) && (field = this.findField(id))){
field.setValue(values[id]);
if(this.trackResetOnLoad){
field.originalValue = field.getValue();
}
}
}
}
return this;
}



findField : function(id) {
var field = this.items.get(id);

if (!Ext.isObject(field)) {
//searches for the field corresponding to the given id. Used recursively for composite fields
var findMatchingField = function(f) {
if (f.isFormField) {
if (f.dataIndex == id || f.id == id || f.getName() == id) {
field = f;
return false;
} else if (f.isComposite) {
return f.items.each(findMatchingField);
}
}
};

this.items.each(findMatchingField);
}
return field || null;
}


It seems that findField only finds the first field with that name or id. I'm a little bit lost doing an override for this and I'm afraid of make anything slow and time consuming...

Could anybody help me or suggest what should I do in order to have anything fast and simple?

Thanks,
Pau

CrazyEnigma
21 May 2010, 1:07 PM
Hmmmm... I think I can help.

Set the form objects with itemId or some arbitrary property consistent to you.


var formpanel = <your formpanel>;
var objs = formpanel.find("itemId", "<your name>");
This returns the array of items found.