PDA

View Full Version : How to REALLY change combobox hidden name ?



mysterty
10 Aug 2011, 1:54 AM
Hello,

I'm adding dynamcaly new comboboxes to my form, and so i need to set their name like "object[0][property]", incrementing the id each times.

But when i do : this.hiddenName = increment(this.hiddenName), it works only once ! /:) (increment is my own method with will get the name and increment the id)

so if i have already 2 items, and i add x dynamicaly i will have something like :
object[0][property]
object[1][property]
object[2][property] // i add first object, the id is incremented
object[2][property] // i add second one, the old id remains "object[1][property]", etc

It seems that this.hiddenName is always "object[1][name]", and when i clone my fields (using cloneConfig), even if i changed their names before, it will keep the old "object[1][property]".

Could you help me please ?

mcadirci
10 Aug 2011, 6:30 AM
Could you please be more clear about what you want to do and what is wrong?

mysterty
10 Aug 2011, 8:22 AM
Ok, i will try...

Here is my code for cloning fields of my forms :

addRelation = function(_caller) {
var parentFieldset = Ext.getCmp($('#'+_caller.id).prev('fieldset').attr('id'));
var prevFieldset = $('#'+_caller.id).prev('fieldset').find('fieldset:last');
prevFieldset = Ext.getCmp(prevFieldset.attr('id'));
nextFieldset = prevFieldset.cloneConfig();
nextFieldset.cascade(prepareFields);
parentFieldset.add(nextFieldset);
parentFieldset.doLayout();
}
/**
* Function preparing fields dupplication
*/
function prepareFields(_target) {
// prepare increment
var nameRE = new RegExp('\\[(\\d+)\\]');
var matches = '';
var tmpName = '';
// Copy store for combo boxes
if(_target.store !== undefined) {
// I get the old field for copiyng his store to the new one
var oldField = $("input[name='"+_target.name+"']:first").next("input");
oldField = Ext.getCmp(oldField.attr('id'));
var records = [];
oldField.store.each(function(r){
records.push(r.copy());
});
var newStore = new Ext.data.Store({
recordType: oldField.store.recordType
});
newStore.add(records);
_target.store = newStore;
tmpName = _target.hiddenName;
matches = nameRE.exec(tmpName);
// #################################
// Here is the problem
// #################################
console.log(_target.name+' '+_target.hiddenName); // Always return for exemple "object[6][property]"
_target.name = _target.hiddenName = tmpName.replace(nameRE, '['+(parseInt(matches[1],10)+1)+']');
console.log(_target.name+' '+_target.hiddenName); // Always return for exemple "object[7][property]"
}
// Change id for auto created fields
if(_target.autoCreate !== undefined) {
_target.autoCreate.id = Ext.id();
tmpName = _target.autoCreate.name;
matches = nameRE.exec(_target.autoCreate.name);
// Here it will becomes "object[7][property]", then "object[8][property]", etc
_target.autoCreate.name = tmpName.replace(nameRE, '['+(parseInt(matches[1],10)+1)+']');
}
}


As you see, i try to change the _target.name and the _target.hiddenName for my cloned comboboxes fields from old "object[x][property]" to new "object[x+1][property]".

My function works fine, but "x" have always the same value for comboboxes, although it correctly changes for others field with "autoCreate" property.

It is as if i didn't changed the name and hiddenName properties !

mysterty
11 Aug 2011, 7:41 AM
As i'm getting annoyed about that, i finaly just count the object number and set it to the id :



var nbFieldset = oldField.parents('fieldset').parents('fieldset').find('fieldset').length;
// ...
_target.name = _target.hiddenName = tmpName.replace(nameRE, '['+nbFieldset+']');

It's really too bad cause it's force me to do not delete a row from the dom but just hide it, and it's more contraint.../:)


If someone found why the name and hiddenName aren't really changed, i would be glad to know it !:-?

thx to all anyway !