Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: Changing fieldLabel dynamically in TextField

  1. #11
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    119
      0  

    Default

    1. Put this directly after including ext-all.js:
    Code:
    Ext.override(Ext.form.Field, {
       setFieldLabel : function(text) {
          this.el.up('.x-form-item', 10, true).child('.x-form-item-label').update(text);
       }
    });
    2. Use:
    Code:
    Ext.getCmp('id-of-your-text-field').setFieldLabel('other label');

  2. #12
    Ext User skaue's Avatar
    Join Date
    Sep 2008
    Location
    Troms
    Posts
    191
    Vote Rating
    0
      0  

    Default

    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

  3. #13
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    119
      0  

    Default

    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;
    		}
    	}
    });

  4. #14
    Ext User skaue's Avatar
    Join Date
    Sep 2008
    Location
    Troms
    Posts
    191
    Vote Rating
    0
      0  

    Default

    yea... thats even more clever... now tell me; why isn't this a part of the API?

  5. #15
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,608
    Vote Rating
    874
      0  

    Default

    Because the form layout is in charge of rendering the labels on form fields. It's a little weird.
    Evan Trimboli
    Twitter - @evantrimboli

  6. #16
    Ext User skaue's Avatar
    Join Date
    Sep 2008
    Location
    Troms
    Posts
    191
    Vote Rating
    0
      0  

    Default

    well.. as long as Condor is around to hand his elite help

  7. #17
    Sencha User sksoft's Avatar
    Join Date
    Jan 2008
    Location
    Moscow, Russia
    Posts
    33
    Vote Rating
    0
      0  

    Default 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;
        }
    });

  8. #18
    Sencha User
    Join Date
    Mar 2011
    Location
    Brazil
    Posts
    1
    Vote Rating
    0
      0  

    Post 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;
    }
    });

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •