Hybrid View
-
1 Nov 2007 4:42 AM #1
change fieldLabel of Ext.form.Field
change fieldLabel of Ext.form.Field
can't figure out how to change the Label of an Ext.form.TextArea component at runtime (after the form has been rendered)
myExtFormTextArea.fieldLabel = 'new label';
doesn't work
maybe someone could give me a hand, thnx
-
1 Nov 2007 5:33 AM #2
You can't just a change a config property after render and expect it do something. You can use Element.up() on the Field's element to find the label entry.
Tim Ryan
Read BEFORE posting a question / BEFORE posting a Bug
Use Google to Search - API / Forum
API Doc (4.x | 3.x | 2.x | 1.x) / FAQ / 1.x->2.x Migration Guide / 2.x->3.x Migration Guide
-
1 Nov 2007 5:43 AM #3
Was just about to post the following, but up() makes more sense!
PHP Code:var TestForm = function(){
return {
init: function(){
var form = new Ext.form.Form();
form.add(new Ext.form.TextField({
fieldLabel: 'First Name',
id:'first',
name: 'first',
width:175
}));
form.render('test-form');
},
changeLabel: function(fieldId, newLabel){
var label = Ext.DomQuery.select(String.format('label[for="{0}"]', fieldId));
if (label){
label[0].childNodes[0].nodeValue = newLabel;
}
}
}
}();
Ext.onReady(TestForm.init, TestForm);
</script>
</head>
<body>
<div id="test-form"></div>
<a href="javascript:TestForm.changeLabel('first', 'Nickname:')">Change</a>
</body>
</html>
-
20 Feb 2008 12:59 PM #4
-
25 Jul 2008 12:19 PM #5
Something like this?
Something like this?
I'm a bit of a noob myself, so please excuse the mess. This seems to work,
And then you could call:PHP Code:Ext.override(Ext.form.Field, {
setLabel: function(text){
var r = this.getEl().up('div.x-form-item');
r.dom.firstChild.firstChild.nodeValue = String.format('{0}', text);
}
});
PHP Code:myTextField = new Ext.form.TextField({..});
myTextField.setLabel('Excellent!');
-
2 Dec 2009 9:01 AM #6
It seems to me that it would be a lot easier to do it this way:
Where component is the form control..
Ext.get(component.getEl().up('div.x-form-item').query('label[for='+component.id+']')[0]).update('you html here')
Last edited by Keith Chadwick; 2 Dec 2009 at 9:23 AM. Reason: query returns dom not El so need to wrap with Ext.get
-
10 Dec 2009 5:40 AM #7Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
I would recommend:
Code:Ext.override(Ext.form.Field, { setFieldLabel : function(text) { if (this.rendered) { this.el.up('.x-form-item', 10, true).child('.x-form-item-label').update(text); } this.fieldLabel = text; } });


Reply With Quote

