PDA

View Full Version : How can I change element's id??



romarybachok
19 Apr 2011, 3:21 PM
I have to change id of element dynamically. But after changing and trying to set value there is an error - object is null:

months_store = new Ext.data.ArrayStore({
fields: ['id', 'month'],
data: [['1', 'January'], ['2', 'February'], ['3', 'March'], ['4', 'April'], ['5', 'May'], ['6', 'June'],
['7', 'July'], ['8', 'August'], ['9', 'September'], ['10', 'October'], ['11', 'November'], ['12', 'December']]
});

combo_months = new Ext.form.ComboBox({
id: '1',
mode: 'local',
store: months_store,
displayField: 'month',
valueField: 'id',
width: 100,
triggerAction: 'all'
});




Ext.getCmp('1').setValue('5');
Ext.getCmp('1').id = '3';
Ext.getCmp('3').setValue('8');//this doesn't work

fay
20 Apr 2011, 12:41 AM
id is a config option, so you can't change it like that. This thread (http://www.sencha.com/forum/showthread.php?33456-how-to-change-an-element-ID&p=157903&viewfull=1#post157903) might work for ya.

mitchellsimoens
20 Apr 2011, 5:43 AM
How about not relying on id? Which is good practice anyway.

Screamy
20 Apr 2011, 6:19 AM
Dynamically changing IDs also may confuse Ext.ComponentMgr...