PDA

View Full Version : checkbox event fires during render



wshpoon
4 Mar 2010, 6:13 AM
When rendering a checkbox, the handler event fires. It also fires when checkbox is checked or unchcked. The strange thing is that it only fires when it is initially rendered unchecked (that's probably because I have checked: true). If I remove the checked: true, it does the opposite and fires only when rendered checked. Thanks

Here is the code:
var siteReportCheckbox = new Ext.form.Checkbox(
{
width: 75,
boxLabel: 'Site',
name: 'sitereport',
id: 'sitereport',
checked: true,
handler: function(){
callSomeFunction();
}
}
);

4 Mar 2010, 6:32 AM
yes, probably because it sets its value at that time.

A work around is to listen to the render of the item, and then set the handler afterwards.

wshpoon
4 Mar 2010, 6:38 AM
kind of silly that you would have to do that, don't you think? I'll try your suggestion.

4 Mar 2010, 6:39 AM
yes, hence my 'work around' comment.

wshpoon
4 Mar 2010, 6:50 AM
Now another silly question. How do you add a handler to a listen event?

I assume you mean something like this:

siteReportCheckbox.on('render', )

But what's the syntax to add a handler? The API doesn't show addHander for checkbox.

4 Mar 2010, 6:52 AM
try setting this.handler - if this is a reference to that checkbox

4 Mar 2010, 6:53 AM
also, the first argument, in most cases where events are fired from an Ext JS class, is the reference to the item sending the event.

wshpoon
4 Mar 2010, 6:59 AM
It still fires. Here is my code:

var siteReportCheckbox = new Ext.form.Checkbox(
{
width: 75,
boxLabel: 'Site',
name: 'sitereport',
id: 'sitereport',
listeners:
{
'render': function(){
this.handler = function(){
writeSiteconfValue('sitereport', this.checked, 'mainstatusbar', 'Site Report');
}
}
}
}
);

4 Mar 2010, 7:02 AM
I really wish you learned to use code tags :P




var siteReportCheckbox = new Ext.form.Checkbox(
{
width: 75,
boxLabel: 'Site',
name: 'sitereport',
id: 'sitereport',
listeners:
{
'render': {
buffer : 100,
fn : function(){
this.handler = function(){
writeSiteconfValue('sitereport', this.checked, 'mainstatusbar', 'Site Report');
}
} }
}
}
);

Try the above example, with a delay, see if that fixes it

4 Mar 2010, 7:04 AM
btw, I can't reproduce your problem with the following example:



var cb = new Ext.form.Checkbox({
checked : true,
handler : function() {
console.log('checked');
}

});

new Ext.Window({
height : 100,
width : 100,
items : cb
}).show();