2
* Ext JS Library 3.0 RC2
3
* Copyright(c) 2006-2009, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.form.Checkbox
11
* @extends Ext.form.Field
12
* Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
14
* Creates a new Checkbox
15
* @param {Object} config Configuration options
18
Ext.form.Checkbox = Ext.extend(Ext.form.Field, {
20
* @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
22
focusClass : undefined,
24
* @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
26
fieldClass: "x-form-field",
28
* @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
32
* @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
33
* {tag: "input", type: "checkbox", autocomplete: "off"})
35
defaultAutoCreate : { tag: "input", type: 'checkbox', autocomplete: "off"},
37
* @cfg {String} boxLabel The text that appears beside the checkbox
40
* @cfg {String} inputValue The value that should go into the generated input element's value attribute
43
* @cfg {Function} handler A function called when the {@link #checked} value changes (can be used instead of
44
* handling the check event). The handler is passed the following parameters:
45
* <div class="mdetail-params"><ul>
46
* <li><b>checkbox</b> : Ext.form.Checkbox<div class="sub-desc">The Checkbox being toggled.</div></li>
47
* <li><b>checked</b> : Boolean<div class="sub-desc">The new checked state of the checkbox.</div></li>
51
* @cfg {Object} scope An object to use as the scope ("this" reference) of the {@link #handler} function
52
* (defaults to this Checkbox).
56
initComponent : function(){
57
Ext.form.Checkbox.superclass.initComponent.call(this);
61
* Fires when the checkbox is checked or unchecked.
62
* @param {Ext.form.Checkbox} this This checkbox
63
* @param {Boolean} checked The new checked value
70
onResize : function(){
71
Ext.form.Checkbox.superclass.onResize.apply(this, arguments);
73
this.el.alignTo(this.wrap, 'c-c');
78
initEvents : function(){
79
Ext.form.Checkbox.superclass.initEvents.call(this);
80
this.mon(this.el, 'click', this.onClick, this);
81
this.mon(this.el, 'change', this.onClick, this);
85
getResizeEl : function(){
90
getPositionEl : function(){
95
* Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
98
markInvalid : Ext.emptyFn,
100
* Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
103
clearInvalid : Ext.emptyFn,
106
onRender : function(ct, position){
107
Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
108
if(this.inputValue !== undefined){
109
this.el.dom.value = this.inputValue;
111
this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
113
this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
118
this.checked = this.el.dom.checked;
123
onDestroy : function(){
124
Ext.destroy(this.wrap);
125
Ext.form.Checkbox.superclass.onDestroy.call(this);
129
initValue : Ext.emptyFn,
132
* Returns the checked state of the checkbox.
133
* @return {Boolean} True if checked, else false
135
getValue : function(){
137
return this.el.dom.checked;
143
onClick : function(){
144
if(this.el.dom.checked != this.checked){
145
this.setValue(this.el.dom.checked);
150
* Sets the checked state of the checkbox.
151
* @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
152
* @return {Ext.form.Field} this
154
setValue : function(v){
155
var checked = this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
156
if(this.el && this.el.dom){
157
this.el.dom.checked = checked;
158
this.el.dom.defaultChecked = checked;
160
this.fireEvent("check", this, checked);
162
this.handler.call(this.scope || this, this, checked);
167
Ext.reg('checkbox', Ext.form.Checkbox);
b'\\ No newline at end of file'