PDA

View Full Version : Dynamically Changing the Form label



murugapradeep
14 Jul 2011, 12:45 AM
Hello,

Is there any way to change the field label in the form dynamically?
if you have any ideas please guide me to do this.


Thanks in advance

AndreaCammarata
14 Jul 2011, 6:39 AM
Hello.
Actually there is not a function like "setLabel" defined for "Ext.form.Field" components that makes you change easily the label value.
However, I wrote you a simple example that show you how to do what you request.




Ext.setup({
onReady: function() {

var form = new Ext.form.FormPanel({
fullscreen: true,
dockedItems: [{
xtype: 'toolbar',
title: 'Example',
items: [{
xtype: 'button',
text: 'Change Label',
handler: function(){

//Set the new label value
form.getComponent('txtFirst').labelEl.dom.innerHTML = 'Hello';

}
}]
}],
items: [{
xtype: 'textfield',
itemId: 'txtFirst',
name : 'first',
label: 'First name'
}]
});
}

});



What I do in this example is take the wanted Field component from the form and then change the innerHTML of the labelEl.

Hope this helps.

murugapradeep
14 Jul 2011, 7:54 PM
Thanks a lot for your reply , I got it.

AndreaCammarata
14 Jul 2011, 11:24 PM
You are welcome.

r4nd7263
5 Aug 2011, 9:29 AM
Why no "setLabel" ?