-
22 Sep 2008 12:57 AM #11Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
1. Put this directly after including ext-all.js:
2. Use:Code:Ext.override(Ext.form.Field, { setFieldLabel : function(text) { this.el.up('.x-form-item', 10, true).child('.x-form-item-label').update(text); } });
Code:Ext.getCmp('id-of-your-text-field').setFieldLabel('other label');
-
22 Sep 2008 1:05 AM #12
Hmm.. got it to work now... It might be the fact that this label was in a popup window (with a form), and I needed to actually display the form first, then I can update the element.
Yea, that would make sense, and I need to stay sane about this
-
22 Sep 2008 1:07 AM #13Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
OK, how about this then:
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); } else { this.fieldLabel = text; } } });
-
22 Sep 2008 1:09 AM #14
yea... thats even more clever... now tell me; why isn't this a part of the API?

-
22 Sep 2008 1:12 AM #15
Because the form layout is in charge of rendering the labels on form fields. It's a little weird.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
22 Sep 2008 1:43 AM #16
well.. as long as Condor is around to hand his elite help

-
1 Mar 2009 2:32 PM #17
The final version
The final version
All of you forgot about labelSeparator

Try to make it carefully...
Code:Ext.override(Ext.form.Field, { setFieldLabel: function(text) { if (this.rendered) { var labelSeparator = this.labelSeparator; if (typeof labelSeparator == 'undefined') { if (this.ownerCt && this.ownerCt.layout && typeof this.ownerCt.layout.labelSeparator != 'undefined') labelSeparator = this.ownerCt.layout.labelSeparator; else labelSeparator = ''; } var formItem = this.el.up('.x-form-item', 10); if (formItem) { var label = formItem.child('.x-form-item-label'); if (label) label.update(text + labelSeparator); } } else this.fieldLabel = text; } });
-
16 Mar 2011 3:59 AM #18
This is more flexible:
This is more flexible:
Code:

Ext.override(Ext.form.Field, {
setFieldLabel: function(text) {
if (this.rendered) {
var labelSeparator = this.labelSeparator;
if (typeof labelSeparator == 'undefined') {
if (this.ownerCt && this.ownerCt.layout && typeof this.ownerCt.layout.labelSeparator != 'undefined')
labelSeparator = this.ownerCt.layout.labelSeparator;
else
labelSeparator = '';
}
var formItem = this.el.up('.x-form-item', 10);
if (formItem) {
var label = formItem.child('.x-form-item-label');
if (label)
label.update(text + labelSeparator);
}
} else
this.fieldLabel = text;
}
});


Reply With Quote