Results 1 to 2 of 2

Thread: Changing Label Text

  1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    6
    Answers
    1
    Vote Rating
    0
      0  

    Question Answered: Changing Label Text

    Simple form with a toggle for switching between metric and inch units. The unitSwitch function also changes all the labels to reflect the current units. The code below works until I uncomment the last line. Then the form hides all the fields except the unit toggle. This line of code is identical to the one three lines up, except the text, so I know it works on it's own.

    Any idea's why it won't work?

    Code:
    var unitSwitch = function(obj){	var tog = obj.getValue();
    	var modelCmp = Ext.getCmp('units');
    
    
    	if (tog) {
    		modelCmp.labelEl.update('Units (Inch)');
    		Ext.getCmp('loadWeight').labelEl.update('Weight (lbs)');
    	} else {
    		modelCmp.labelEl.update('Units (Metric)');
    		//Ext.getCmp('loadWeight').labelEl.update('Weight (kg)');
    	}
    }

    Also, why does the font style change when the label is updated from load state? So far I haven't touched any css code from sencha.

    Thanks

  2. Hi runner.
    What is the error you get if you uncomment the last line of code?

    About the font change:
    That's normal because actually updating the labelEl content in that way, you delete the span element which is inside each form label.
    You should write:

    Code:
    modelCmp.labelEl.update('<span>Units (Inch)</span>');
    or

    Code:
    modelCmp.labelEl.dom.firstChild.innerHTML = 'Hello';
    Hope this helps.

  3. #2
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Location
    Italy
    Posts
    1,395
    Answers
    148
    Vote Rating
    24
      0  

    Default

    Hi runner.
    What is the error you get if you uncomment the last line of code?

    About the font change:
    That's normal because actually updating the labelEl content in that way, you delete the span element which is inside each form label.
    You should write:

    Code:
    modelCmp.labelEl.update('<span>Units (Inch)</span>');
    or

    Code:
    modelCmp.labelEl.dom.firstChild.innerHTML = 'Hello';
    Hope this helps.
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


Tags for this Thread

Posting Permissions

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