PDA

View Full Version : [3.0.3] Checkboxgroup - (De)Select All



squ3lch
16 Nov 2009, 6:50 AM
I have the following action:
var deselectQueues = new Ext.Action({
text: 'Deselect All',
handler: function(){
Ext.each(Ext.getCmp('queuesChkBxGp').items.items, function(item) {
alert(item.id);
}, Ext.getCmp('queuesChkBxGp'));
}
});It is called by a button and references the following checkboxgroup:
{
xtype: 'checkboxgroup',
cls: 'chkbxGrpIndent',
id: 'queuesChkBxGp',
hideLabel:true,
columns:1,
border:false,
items:[

{boxLabel: 'Queue 1',name: 'filter-q-m-48',id:'filter-q-m-48',checked:true},
{boxLabel: 'Queue 2',name: 'filter-q-m-1',id:'filter-q-m-1',checked:true}

]
}When I click the button, I receive one JS alert with "undefined" as the message, where I would expect to receive two consecutive alerts each with a different id. Is my each syntax correct? Have I missed something else?

Thanks in advance.

Condor
16 Nov 2009, 7:16 AM
I would use:

Ext.getCmp('queuesChkBxGp').items.each(function(cb){
cb.setValue(false);
});

(but this only works AFTER the checkboxgroup is rendered!)

squ3lch
16 Nov 2009, 7:24 AM
Thanks Condor.

The checkboxgroup is rendered before the button is pressed, as the button is rendered into the tbar of a tabpanel tab item, and the checkboxgroup is in the items array for that tab.

However, when I use your method I receive an error telling me that cb doesn't support the getValue method. I then changed the code to again alert cb.id, and it gave me a generated ext-comp-x id.

squ3lch
16 Nov 2009, 8:42 AM
Well, I couldn't get each to return anything useful so I rewrote it to use DomQuery. It seems like the long way around but it works.
var deselectQueues = new Ext.Action({
text: 'Deselect All',
handler: function(){
Ext.DomQuery.select('*[id^=filter-q-m]').each(function(cb){
cb.setValue(false);
});
}
});