最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do you check a checkbox without firing a change event? - Stack Overflow

programmeradmin1浏览0评论

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 ).

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 ).

Share Improve this question edited Oct 28, 2019 at 16:38 Brian Tompsett - 汤莱恩 5,88372 gold badges61 silver badges133 bronze badges asked May 11, 2011 at 8:53 BdfyBdfy 24.6k58 gold badges135 silver badges180 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 29

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

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;

Why dont you just set

r.checked = true, 

does that not work? although it should work.

I was already trying the accepted answer before googling but it didn't work in 4.1.3. The following did:

myCheckBox.setRawValue(true);

Hope this helps future googlers.

Calling suspendEvents(false) before setting the value and resumeEvents() afterwards is a more generic approach than setRawValue because if you're using converters (say, 1 is true and 0 is false) they will remain working.

发布评论

评论列表(0)

  1. 暂无评论