Afflatus
Afflatus

Reputation: 943

How to marked only one of the menu items in Extjs menu checked

I have a menu added to a button.

buttons.push({
        iconCls: 'fa fa-money',
        text: 'Currency format',
        menu: new Ext.menu.Menu(
        {
            items: [{
                iconCls: 'fa fa-euro',
                text: '1.000,00',
                checked: true,
                handler: function (btn) {
                    updateNumericFormat(btn);
                }
            },
            {
                iconCls: 'fa fa-dollar',
                text: '1,000.00',
                checked: false,
                handler: function (btn) {
                    updateNumericFormat(btn);
                }
            }],

        })
    });

I would like to select only one item in the menu at the time. so if the first item is checked I want the other item to be unchecked. but I can't get it to work.

updateNumericFormat: function (btn) {
    //uncheck the other button
}

Upvotes: 1

Views: 826

Answers (2)

Yogen Darji
Yogen Darji

Reputation: 3300

sencha fiddle

updateNumericFormat: function (btn) {
      btn.up().down('[name=euro]').setChecked(!btn.checked , true);
}

Full code,

Ext.create('Ext.menu.Menu', {
            width: 100,
            margin: '0 0 10 0',
            floating: false, // usually you want this set to True (default)
            renderTo: Ext.getBody(), // usually rendered by it's containing component
            items: [{
                iconCls: 'fa fa-euro',
                text: '1.000,00',
                checked: true,
                name : 'euro',
                handler: function (btn) {
                   btn.up().down('[name=dollar]').setChecked(!btn.checked , true);
                }
            },
            {
                iconCls: 'fa fa-dollar',
                text: '1,000.00',
                checked: false,
                name: 'dollar',
                handler: function (btn) {
                      btn.up().down('[name=euro]').setChecked(!btn.checked , true);
                }
            }]
        });

Upvotes: 1

Alexander
Alexander

Reputation: 20244

What you are searching is the menucheckitem's group config, or maybe even a cycle button.

Upvotes: 0

Related Questions