PDA

View Full Version : Checkbox - Event "Check" fires while loading data



dalder
25 Jun 2010, 12:28 AM
In the following example I try to load a checkbox from php via extdirect.
Every thing works fine for loading and submitting.

But during load the checkbox fires the "check" event and saves the data.
Would you add x checkboxes it saves x times the data to server.

However, it just have to save the data if I click the checkbox.

Do I use the wrong event or is this a bug(http://www.sencha.com/forum/showthread.php?31118-2.0.2-FIXED-Checkbox-sends-quot-check-quot-event-while-being-rendered)?



var testform = new Ext.form.FormPanel ({
items: [{
xtype: 'checkbox',
fieldLabel: 'Label 1',
name: 'label1',
listeners: ({
'check': function() {
safeFormData();
}
})
}],
api: {
load: Ext.ss.class.load,
submit: Ext.ss.class.submit
},
listeners: ({
'afterrender': function(){
loadFormData();
}
})
});

function loadFormData() {
testform.load();
}

function safeFormData() {
testform.getForm().submit({
waitMsg: 'Save settings...'
});
}
Ext Js Version: 3.2.1

Animal
25 Jun 2010, 1:24 AM
I think it's a bug. The event should not fire during form load.

dalder
30 Jun 2010, 3:58 AM
Is there a way to fix the bug or do I have to wait for the next public release?

Animal
30 Jun 2010, 4:04 AM
Not sure. Do a search in the bug folder, and if you can't see it reported already, file a report.

dalder
12 Oct 2010, 4:56 AM
i've updated to extjs 3.3.0.
but the event "check" still fired if the data loaded with load() from direct store.
is it possible to detect just the click event?

Animal
12 Oct 2010, 5:52 AM
I think it's a bug. Here's the fix, and feel free to report it.



Ext.override(Ext.form.Checkbox, {
onClick : function(){
if(this.el.dom.checked != this.checked){
this.setValue(this.el.dom.checked, true);
}
},

/**
* Sets the checked state of the checkbox, fires the 'check' event, and calls a
* <code>{@link #handler}</code> (if configured).
* @param {Boolean/String} checked The following values will check the checkbox:
* <code>true, 'true', '1', or 'on'</code>. Any other value will uncheck the checkbox.
* @return {Ext.form.Field} this
*/
setValue : function(v, fireCheck){
var checked = this.checked,
inputVal = this.inputValue;

this.checked = (v === true || v === 'true' || v == '1' || (inputVal ? v == inputVal : String(v).toLowerCase() == 'on'));
if(this.rendered){
this.el.dom.checked = this.checked;
this.el.dom.defaultChecked = this.checked;
}
if (fireCheck && (checked != this.checked)){
this.fireEvent('check', this, this.checked);
if(this.handler){
this.handler.call(this.scope || this, this, this.checked);
}
}
return this;
}
});

dalder
13 Oct 2010, 12:31 AM
thx! works fine!
posted a bug report: http://www.sencha.com/forum/showthread.php?112339-PENDING-Checkbox-Event-quot-Check-quot-fires-while-loading-data&p=524267

wshpoon
28 Jan 2011, 11:45 AM
My radiogroup no longer fires on check once this override was implemented. Works with the checkbox.