DeLe
DeLe

Reputation: 2480

Extjs - change checkbox label

i have a xtype "checkbox", i want change boxlabel by dynamic

{
    xtype:'checkbox',
    id: 'abc',
    checked: false,
    uncheckedValue: '0',
    inputValue: 1,
    boxLabel: 'change',
    name:'abc'
}

i using

Ext.getCmp('abc').setBoxLabel('not working'); // it's not working

or

Ext.getCmp('abc').update('loss checkbox'); // it's working but checkbox's disappear.

How can i do that? thanks

Upvotes: 3

Views: 6919

Answers (3)

code4jhon
code4jhon

Reputation: 6044

A cleaner approach (IMO)

For ExtJs 4.1.1 (this was officially added in later versions of the framework)

I found the override recommended by Condor https://www.sencha.com/forum/showthread.php?71968-Set-Checkbox-boxLabel-dynamically to be the best option because this works even if the checkbox is not rendered which is not the case in DrakES solution.

Ext.override(Ext.form.Checkbox, {
    setBoxLabel: function(boxLabel){
        this.boxLabel = boxLabel;
        if(this.rendered){
            //NOTICE I CHANGED THIS LINE FROM THE ONE IN THE ORIGINAL SENCHA FORUM
            this.getEl().down('label.x-form-cb-label').update('New Label');
        }
    }
});

Now you can use .setBoxLabel() :)

Upvotes: 0

Greendrake
Greendrake

Reputation: 3734

In Ext JS 4.2+ use setBoxLabel()

In Ext JS 4.1+ I've just found this workaround can help:

Ext.getCmp('abc').getEl().down('label.x-form-cb-label').update('New Label')

Upvotes: 4

rixo
rixo

Reputation: 25041

getBoxLabel should be working (see this jsFiddle).

Maybe what you want to use is fieldLabel and setFieldLabel?

Upvotes: 1

Related Questions