tobiu
9 Feb 2010, 2:00 PM
hi together,
i know, i should not reset forms that are not rendered yet, though from time to time it happens ;)
in this case, the checkbox has the config
checked:true
since the element is not rendered yet, the reset leads to a call of setValue(undefined). in that case, the checkbox loses its checked-state because the event check gets fired.
i can show it in a simple demo:
Ext.onReady(function(){
Ext.ns('app');
app.win = new Ext.Window({
width : 400
,height : 400
,items :
app.form = new Ext.form.FormPanel({
labelWidth : 175
,items : [
new Ext.form.Checkbox({
checked : true
,boxLabel : 'active'
,fieldLabel : 'check'
,labelSeparator : ''
,width : 170
,listeners:{
check: function(box, checked){
console.log('check: ' + checked);
}
}
})
]
})
});
app.form.getForm().reset();
app.win.show();
});
we are lucky, this can be fixed with a single line of code. here is the hotfix:
Ext.form.Checkbox.override({
setValue : function(v){
if(v === undefined)return;
var checked = this.checked ;
this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
if(this.rendered){
this.el.dom.checked = this.checked;
this.el.dom.defaultChecked = this.checked;
}
if(checked != this.checked){
this.fireEvent('check', this, this.checked);
if(this.handler){
this.handler.call(this.scope || this, this, this.checked);
}
}
return this;
}
});
kind regards,
tobiu
i know, i should not reset forms that are not rendered yet, though from time to time it happens ;)
in this case, the checkbox has the config
checked:true
since the element is not rendered yet, the reset leads to a call of setValue(undefined). in that case, the checkbox loses its checked-state because the event check gets fired.
i can show it in a simple demo:
Ext.onReady(function(){
Ext.ns('app');
app.win = new Ext.Window({
width : 400
,height : 400
,items :
app.form = new Ext.form.FormPanel({
labelWidth : 175
,items : [
new Ext.form.Checkbox({
checked : true
,boxLabel : 'active'
,fieldLabel : 'check'
,labelSeparator : ''
,width : 170
,listeners:{
check: function(box, checked){
console.log('check: ' + checked);
}
}
})
]
})
});
app.form.getForm().reset();
app.win.show();
});
we are lucky, this can be fixed with a single line of code. here is the hotfix:
Ext.form.Checkbox.override({
setValue : function(v){
if(v === undefined)return;
var checked = this.checked ;
this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
if(this.rendered){
this.el.dom.checked = this.checked;
this.el.dom.defaultChecked = this.checked;
}
if(checked != this.checked){
this.fireEvent('check', this, this.checked);
if(this.handler){
this.handler.call(this.scope || this, this, this.checked);
}
}
return this;
}
});
kind regards,
tobiu