Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you check a checkbox without firing a change event?

I have simple checkbox:

r = new Ext.form.Checkbox({
    listeners: {
        check: function(checkbox, checked) {
        }
    }
}

r.setValue(true);

How to check checkbox without fireevent check ( I want to fireevent check ONLY from mouse click ) ? (setValue doesn't work ).

like image 222
Bdfy Avatar asked May 11 '11 08:05

Bdfy


3 Answers

You should suspend events before set the value and resume events after this. For example:

myCheckBox.suspendEvents(false); // Stop all events. 
                                 //Be careful with it. Dont forget resume events!
myCheckBox.setValue(!myCheckBox.getValue()); // invert value
myCheckBox.resumeEvents(); // resume events
like image 188
Selmaril Avatar answered Nov 18 '22 23:11

Selmaril


Why dont you just set r.checked = true, does that not work?

Setting checked attributes will have affect only for non-rendered control to assign initial control value. After rendering you can't use this to change value.

Suspend/Resume events is good practice to change control value without sending notifications.

Also you can put checked state immedially to dom element:

item.el.dom.checked = true;

like image 38
VadimB Avatar answered Nov 18 '22 22:11

VadimB


Why dont you just set

r.checked = true, 

does that not work? although it should work.

like image 34
Lev Avatar answered Nov 19 '22 00:11

Lev