PDA

View Full Version : [CLOSED-548] Ext.form.Checkbox



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

Jamie Avins
11 Feb 2010, 12:41 PM
Unfortunately a change like this would alter current functionality, we cannot implement a workaround like this for everyone.

tobiu
11 Feb 2010, 12:44 PM
hi jamie,

could you please, if possible, explain in short terms what behaviour changes with the fix? then i could improve it further, if it is not too huge.


thx, tobiu

Jamie Avins
11 Feb 2010, 1:36 PM
If anyone calls setValue() on a checkbox (without any arguments) it currently will clear the check, your change would mean this no longer happens.