📄 checkbox.js
字号:
/** * @class Ext.form.Checkbox * @extends Ext.form.Field * 单独的checkbox域,可以直接代替传统checkbox域 * @constructor * 创建一个新的CheckBox对象 * @param {Object} config 配置项选项 *//** * @class Ext.form.Checkbox * @extends Ext.form.Field * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields. * @constructor * Creates a new Checkbox * @param {Object} config Configuration options */Ext.form.Checkbox = function(config){ Ext.form.Checkbox.superclass.constructor.call(this, config); this.addEvents({ /** * @event check * 当checkbox被单击时触发事件,无论有选中还是没有选中。 * @param {Ext.form.Checkbox} this 表示当前checkbox * @param {Boolean} checked 选中的值 */ /** * @event check * Fires when the checkbox is checked or unchecked. * @param {Ext.form.Checkbox} this This checkbox * @param {Boolean} checked The new checked value */ check : true });};Ext.extend(Ext.form.Checkbox, Ext.form.Field, { /** * checkbox得到焦点时所使用的样式表(css)默认为undefined */ /** * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined) */ focusClass : undefined, /** * checkbox默认的样式表(css)默认为x-form-field */ /** * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field") */ fieldClass: "x-form-field", /** * @cfg {Boolean} checked 如果checkbox需要呈现选中状态,设置checked为True(默认为false) */ /** * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false) */ checked: false, /** * @cfg {String/Object} autoCreate 一个DomHelper创建元素的对象,或者为true,表示采用默认的方式创建元素。(默认为 * {tag: "input", type: "checkbox", autocomplete: "off"}) */ /** * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to * {tag: "input", type: "checkbox", autocomplete: "off"}) */ defaultAutoCreate : { tag: "input", type: 'checkbox', autocomplete: "off"}, /** * @cfg {String} boxLabel checkbox旁边显示的文字 * */ /** * @cfg {String} boxLabel The text that appears beside the checkbox */ /** * @cfg {String} inputValue 导出input元素属性值 */ /** * @cfg {String} inputValue The value that should go into the generated input element's value attribute */ // onResize : function(){ Ext.form.Checkbox.superclass.onResize.apply(this, arguments); if(!this.boxLabel){ this.el.alignTo(this.wrap, 'c-c'); } }, initEvents : function(){ Ext.form.Checkbox.superclass.initEvents.call(this); this.el.on("click", this.onClick, this); this.el.on("change", this.onClick, this); }, getResizeEl : function(){ return this.wrap; }, getPositionEl : function(){ return this.wrap; }, // private onRender : function(ct, position){ Ext.form.Checkbox.superclass.onRender.call(this, ct, position); if(this.inputValue !== undefined){ this.el.dom.value = this.inputValue; } this.wrap = this.el.wrap({cls: "x-form-check-wrap"}); if(this.boxLabel){ this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel}); } if(this.checked){ this.setValue(true); }else{ this.checked = this.el.dom.checked; } }, // private initValue : Ext.emptyFn, /** * 返回checkbox的选择状态 * @return {Boolean} True表示为已选中,否则false */ /** * Returns the checked state of the checkbox. * @return {Boolean} True if checked, else false */ getValue : function(){ if(this.rendered){ return this.el.dom.checked; } return false; }, // private onClick : function(){ if(this.el.dom.checked != this.checked){ this.setValue(this.el.dom.checked); } }, /** * 设置checkbox的选择状态 * @param {Boolean/String} 传入的参数可以为boolean或者String类型,值为True, 'true,' 或 '1'都表示选中,其他为没有选中 */ /** * Sets the checked state of the checkbox. * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it. */ setValue : function(v){ this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on'); if(this.el && this.el.dom){ this.el.dom.checked = this.checked; this.el.dom.defaultChecked = this.checked; } this.fireEvent("check", this, this.checked); }});Ext.reg('checkbox', Ext.form.Checkbox);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -