-
29 Apr 2011 4:59 AM #1
Ext.form.field.Base component with setFieldLabel procedure (4.x)
Ext.form.field.Base component with setFieldLabel procedure (4.x)
Code:Ext.override(Ext.form.field.Base, { setFieldLabel: function($Label) { this.fieldLabel = $Label; Ext.get(this.getEl().query("label")[0]).update(this.fieldLabel+this.labelSeparator); } });
-
2 May 2011 10:50 PM #2
Code:Ext.override(Ext.form.field.Base, { setFieldLabel: function($Label) { this.fieldLabel = $Label; var $loc_Separator = this.labelSeparator; var $loc_Element = Ext.get(this.getEl().query("label")[0]); if(/after/.test($loc_Element.dom.className)) { $loc_Separator = ""; } Ext.get(this.getEl().query("label")[0]).update(this.fieldLabel+$loc_Separator); } });
-
9 May 2011 7:04 AM #3
Thanks for the v4 of this override. I'd been using a similar override in v3 that included
.Code:getFieldLabel
I see that they addedmethod to the API in v4. It seems like an oversite that they didn't addCode:getFieldLabel
as well.Code:setFieldLabel
This is something that really should be part of the native API.
-
9 May 2011 7:50 AM #4
Here's my version of this override which uses the "labelEl" property instead of a DOM query to find the label element:
Code:Ext.override(Ext.form.Field.Base, { setFieldLabel : function(text) { var labelSeparator = ':'; if (typeof this.labelSeparator !== 'undefined') { labelSeparator = this.labelSeparator; } var label = this.labelEl; if (label !== null) { label.update(text + labelSeparator); } } });
-
12 May 2011 11:38 AM #5
-
15 May 2011 11:11 PM #6
Final code:
Code:// overrides Ext.override(Ext.form.field.Base, { // Hozzáadott kód setFieldLabel: function($Label) { var $loc_Separator = ""; var $loc_Element = null; this.fieldLabel = $Label; if(Ext.isDefined(this.labelEl) && this.labelEl !== null) { $loc_Element = this.labelEl; } else { $loc_Element = Ext.get(this.getEl().query("label")[0]); // CheckBox boxLabel } $loc_Separator = (Ext.isDefined(this.labelSeparator)) ? this.labelSeparator : ":"; if(/after/.test($loc_Element.dom.className)) { // CheckBox boxLabel $loc_Separator = ""; } if($loc_Element !== null) { $loc_Element.update(this.fieldLabel+$loc_Separator); } } });
-
21 Jul 2011 5:43 PM #7
Error in final code
Error in final code
Dear Gents, Thanks for the code, however I get an error with the following line of code:
$loc_Element = Ext.get(this.getEl().query("label")[0]); // CheckBox boxLabel
I get, "this.getEl() is undefined", I am using the latest version of Sencha 4.0.2a.
Is anyone else getting this error? Is there a fix?
Cheers
-
22 Jul 2011 5:12 PM #8
Hi jamone,
Please write your code, which uses the setFieldLabel procedure.
I have a 4.0.2 version works well.
Thanks.
-
22 Jul 2011 10:20 PM #9
this.getEl() fails if the component is not rendered yet. The override can check for the this.rendered property and just update the fieldLabel property in this case.
-
27 Jul 2011 2:05 AM #10
I do not have any checkboxes in my code, just field labels.
I have the following in my code, and I get the error.
Ext.override(Ext.form.field.Base, {
// Hozz?adott k?d
setFieldLabel: function($Label) {
var $loc_Separator = "";
var $loc_Element = null;
this.fieldLabel = $Label;
if(Ext.isDefined(this.labelEl) && this.labelEl !== null) {
$loc_Element = this.labelEl;
}
else {
$loc_Element = Ext.get(this.getEl().query("label")[0]); // CheckBox boxLabel
}
$loc_Separator = (Ext.isDefined(this.labelSeparator)) ? this.labelSeparator : ":";
if(/after/.test($loc_Element.dom.className)) { // CheckBox boxLabel
$loc_Separator = "";
}
if($loc_Element !== null) {
$loc_Element.update(this.fieldLabel+$loc_Separator);
}
}
});
TypeError: Result of expression 'this.getEl()' [undefined] is not an object.
If I comment out the following:
else {
$loc_Element = Ext.get(this.getEl().query("label")[0]); // CheckBox boxLabel
}
$loc_Separator = (Ext.isDefined(this.labelSeparator)) ? this.labelSeparator : ":";
if(/after/.test($loc_Element.dom.className)) { // CheckBox boxLabel
$loc_Separator = "";
}
It works fine. I believe the code needs to check if the CheckBox is rendered and deal with it appropriately.
Similar Threads
-
How to get a parent form of a field as a Component
By asmdec in forum Ext 2.x: Help & DiscussionReplies: 16Last Post: 25 Mar 2011, 10:43 AM -
customized field: how to add ext component above a field onRender?
By bbimber in forum Ext 3.x: Help & DiscussionReplies: 1Last Post: 13 Jan 2011, 2:07 PM -
Form fieldlabel : button (or component) instead of text as field label
By mailme_gx in forum Ext 3.x: Help & DiscussionReplies: 4Last Post: 14 Sep 2009, 11:20 PM -
The Ext base forces application/x-www-form-urlencoded as the content type
By dotnetCarpenter in forum Ext 1.x: BugsReplies: 12Last Post: 29 Mar 2008, 11:11 PM


Reply With Quote