3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.menu.CheckItem
9 * @extends Ext.menu.Item
10 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
12 * Creates a new CheckItem
13 * @param {Object} config Configuration options
14 * @xtype menucheckitem
16 Ext.menu.CheckItem = function(config){
17 Ext.menu.CheckItem.superclass.constructor.call(this, config);
20 * @event beforecheckchange
21 * Fires before the checked value is set, providing an opportunity to cancel if needed
22 * @param {Ext.menu.CheckItem} this
23 * @param {Boolean} checked The new checked value that will be set
28 * Fires after the checked value has been set
29 * @param {Ext.menu.CheckItem} this
30 * @param {Boolean} checked The checked value that was set
35 * A function that handles the checkchange event. The function is undefined by default, but if an implementation
36 * is provided, it will be called automatically when the checkchange event fires.
37 * @param {Ext.menu.CheckItem} this
38 * @param {Boolean} checked The checked value that was set
39 * @method checkHandler
41 if(this.checkHandler){
42 this.on('checkchange', this.checkHandler, this.scope);
44 Ext.menu.MenuMgr.registerCheckable(this);
46 Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, {
49 * All check items with the same group name will automatically be grouped into a single-select
50 * radio button group (defaults to '')
53 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
55 itemCls : "x-menu-item x-menu-check-item",
57 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
59 groupClass : "x-menu-group-item",
62 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
63 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
64 * initialized with checked = true will be rendered as checked.
69 ctype: "Ext.menu.CheckItem",
72 onRender : function(c){
73 Ext.menu.CheckItem.superclass.onRender.apply(this, arguments);
75 this.el.addClass(this.groupClass);
79 this.setChecked(true, true);
85 Ext.menu.MenuMgr.unregisterCheckable(this);
86 Ext.menu.CheckItem.superclass.destroy.apply(this, arguments);
90 * Set the checked state of this item
91 * @param {Boolean} checked The new checked value
92 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
94 setChecked : function(state, suppressEvent){
95 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
97 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
100 if(suppressEvent !== true){
101 this.fireEvent("checkchange", this, state);
107 handleClick : function(e){
108 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
109 this.setChecked(!this.checked);
111 Ext.menu.CheckItem.superclass.handleClick.apply(this, arguments);
114 Ext.reg('menucheckitem', Ext.menu.CheckItem);