PDA

View Full Version : On Change event is not getting triggered if I add checkboxes dynamically to checkbox



agarapati
12 May 2015, 6:09 AM
I have two checkbox group components in screen, when I add all checkboxes to checkboxgroup component in view able to see on change event getting triggered.



{
xtype: 'checkboxgroup',
itemId: 'categorySection',
id: 'categorySection',
vertical: true,
padding: '10 0 0 0',
layout: 'fit',
items: [{
xtype:'checkbox',
boxLabel: 'Chk1',
checked: false,
name: 'riskFilter',
inputValue: 'chk1'
},{
xtype:'checkbox',
boxLabel: 'Chk2',
checked: false,
name: 'riskFilter',
inputValue: 'chk2'
}]
},





When I add checkboxes to checkbox group after page load, the change event is not getting triggered on the checkbox group.

View code part:-




{
xtype: 'checkboxgroup',
itemId: 'categorySection',
id: 'categorySection',
vertical: true,
padding: '10 0 0 0',
layout: 'fit',
items: [],
listeners:{
'change':'mthName2'
} }, {
xtype: 'checkboxgroup',
itemId: 'riskSection',
id: 'riskSection',
vertical: true,
padding: '10 0 0 0',
layout: 'fit',
items: [],
listeners:{
'change':'mthName'
}
}



Controller Part Code:-




handleAssetsDataLoad:function(chkBoxGrpObj, store){
var Items;
var ChkBoxGrp = chkBoxGrpObj.items;
store.each(function(item) {
Items = new Ext.form.Checkbox({
boxLabel: item.data.name,
checked: false,
name: 'assetFilter',
inputValue: item.data.name
});
ChkBoxGrp.add(assetItems);
});
},


In both cases I have same look and feel experience, only difference is with change event triggering.

tristan.lee
13 May 2015, 7:58 PM
Can you create a fiddle (https://fiddle.sencha.com) or provide a more complete code sample to test against? I created this simple test case with 6 checkboxes in a checkboxgroup. I then dynamically added a checkbox to the group and it triggers change event.

mpp

agarapati
9 Jun 2015, 6:45 AM
Hi lee,
https://fiddle.sencha.com/#fiddle/o9n

I created code in Fiddle, In the controller app/controller/Home.js under onLaunch method I wrote code to add checkboxes to checkboxgroup dynamically. Able to see the checkboxes on selecting My Investments Radio buttons on the top.

The Change event is not getting triggered, I added listeners in the view app/view/Home.js

tristan.lee
10 Jun 2015, 12:42 PM
In your controller, you were adding the checkboxes to the group using the items property. add() should be called directly on the checkboxgroup component.

Also, the event is change, not checkchange. Fixing these 2 things calls the listeners as you'd expect.

odm