/*! * Ext JS Library 3.4.0 * Copyright(c) 2006-2011 Sencha Inc. * licensing@sencha.com * http://www.sencha.com/license */ /** * @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 * @xtype checkbox */ Ext.form.Checkbox = Ext.extend(Ext.form.Field, { /** * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined) */ focusClass : undefined, /** * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to 'x-form-field') */ fieldClass : 'x-form-field', /** * @cfg {Boolean} checked true if the checkbox should render initially checked (defaults to false) */ checked : false, /** * @cfg {String} boxLabel The text that appears beside the checkbox */ boxLabel: ' ', /** * @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} inputValue The value that should go into the generated input element's value attribute */ /** * @cfg {Function} handler A function called when the {@link #checked} value changes (can be used instead of * handling the check event). The handler is passed the following parameters: *
{@link #handler}
(if configured).
* @param {Boolean/String} checked The following values will check the checkbox:
* true, 'true', '1', or 'on'
. Any other value will uncheck the checkbox.
* @return {Ext.form.Field} this
*/
setValue : function(v){
var checked = this.checked,
inputVal = this.inputValue;
if (v === false) {
this.checked = false;
} else {
this.checked = (v === true || v === 'true' || v == '1' || (inputVal ? v == inputVal : String(v).toLowerCase() == 'on'));
}
if(this.rendered){
this.el.dom.checked = this.checked;
this.el.dom.defaultChecked = this.checked;
}
if(checked != this.checked){
this.fireEvent('check', this, this.checked);
if(this.handler){
this.handler.call(this.scope || this, this, this.checked);
}
}
return this;
}
});
Ext.reg('checkbox', Ext.form.Checkbox);