Reputation: 20244
I have a checkboxgroup as defined below. (The checkboxgroup has a 'change' event defined in a controller which I hope doesn't matter here.)
The handlers show the following problem:
undefined
.What am I doing wrong, or how could I possibly get the references correct?
Ext.define('MyApp.CheckItems', {
extend : 'Ext.form.CheckboxGroup',
defaults : {
margin : "0 10 0 0"
},
...
handleUncheckOne:function(checkbox,checked) {
console.log(checkbox.up('checkboxgroup'));
// Output depends on whether it is a startItems checkbox one or a new one...
},
initComponent : function() {
var list = [{
xtype:'checkbox',
boxLabel: "All",
name: "#ALL#",
inputValue: "#ALL#",
checked : false,
handler: me.handleCheckAll
}];
Ext.each(startItems, function(entry, i) {
list.push( {
boxLabel : entry.label,
name : entry.name,
inputValue : entry.value,
checked : true,
handler : me.handleUncheckOne
});
});
Ext.applyIf(me, {
items : list
});
me.callParent(arguments);
},
addToList:function(names) {
var me = this;
var list = [];
Ext.each(names,function(entry) {
list.push(Ext.create('Ext.form.field.Checkbox',Ext.applyIf(Ext.clone(me.defaults),{
boxLabel : entry.label,
name : entry.name,
inputValue : entry.value,
checked : true,
handler : me.handleUncheckOne,
listeners : {
change: function() {
me.fireEvent("change") // Fire change event on checkboxgroup
}
}
})));
});
if(list.length>0) {
me.items.addAll(list);
me.doLayout();
}
}
Upvotes: 0
Views: 76
Reputation: 25041
You can't directly modify the items collection like that. Doing so, you circumvent some code that would set the ownerCt
property of the new checkbox, which explain why the up
query is not working.
Your code should rather looks like this:
addToList: function(names) {
var me = this; // hope this it the checkbox group
var list = [];
Ext.each(names, function(entry) {
// adding with the container's add method
me.add(new Ext.form.field.Checkbox(Ext.applyIf({
boxLabel : entry.label,
name : entry.name,
inputValue : entry.value,
checked : true,
handler : me.handleUncheckOne,
listeners : {
change: function() {
me.fireEvent("change") // Fire change event on checkboxgroup
}
}
}, me.defaults)));
});
}
Upvotes: 2