3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.form.Checkbox"></div>/**
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, {
19 <div id="cfg-Ext.form.Checkbox-focusClass"></div>/**
20 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
22 focusClass : undefined,
23 <div id="cfg-Ext.form.Checkbox-fieldClass"></div>/**
24 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to 'x-form-field')
26 fieldClass : 'x-form-field',
27 <div id="cfg-Ext.form.Checkbox-checked"></div>/**
28 * @cfg {Boolean} checked <tt>true</tt> if the checkbox should render initially checked (defaults to <tt>false</tt>)
31 <div id="cfg-Ext.form.Checkbox-autoCreate"></div>/**
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'},
36 <div id="cfg-Ext.form.Checkbox-boxLabel"></div>/**
37 * @cfg {String} boxLabel The text that appears beside the checkbox
39 <div id="cfg-Ext.form.Checkbox-inputValue"></div>/**
40 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
42 <div id="cfg-Ext.form.Checkbox-handler"></div>/**
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>
50 <div id="cfg-Ext.form.Checkbox-scope"></div>/**
51 * @cfg {Object} scope An object to use as the scope ('this' reference) of the {@link #handler} function
52 * (defaults to this Checkbox).
59 initComponent : function(){
60 Ext.form.Checkbox.superclass.initComponent.call(this);
62 <div id="event-Ext.form.Checkbox-check"></div>/**
64 * Fires when the checkbox is checked or unchecked.
65 * @param {Ext.form.Checkbox} this This checkbox
66 * @param {Boolean} checked The new checked value
73 onResize : function(){
74 Ext.form.Checkbox.superclass.onResize.apply(this, arguments);
75 if(!this.boxLabel && !this.fieldLabel){
76 this.el.alignTo(this.wrap, 'c-c');
81 initEvents : function(){
82 Ext.form.Checkbox.superclass.initEvents.call(this);
90 <div id="method-Ext.form.Checkbox-markInvalid"></div>/**
92 * Overridden and disabled. The editor element does not support standard valid/invalid marking.
95 markInvalid : Ext.emptyFn,
96 <div id="method-Ext.form.Checkbox-clearInvalid"></div>/**
98 * Overridden and disabled. The editor element does not support standard valid/invalid marking.
101 clearInvalid : Ext.emptyFn,
104 onRender : function(ct, position){
105 Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
106 if(this.inputValue !== undefined){
107 this.el.dom.value = this.inputValue;
109 this.wrap = this.el.wrap({cls: 'x-form-check-wrap'});
111 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
116 this.checked = this.el.dom.checked;
118 // Need to repaint for IE, otherwise positioning is broken
122 this.resizeEl = this.positionEl = this.wrap;
126 onDestroy : function(){
127 Ext.destroy(this.wrap);
128 Ext.form.Checkbox.superclass.onDestroy.call(this);
132 initValue : function() {
133 this.originalValue = this.getValue();
136 <div id="method-Ext.form.Checkbox-getValue"></div>/**
137 * Returns the checked state of the checkbox.
138 * @return {Boolean} True if checked, else false
140 getValue : function(){
142 return this.el.dom.checked;
148 onClick : function(){
149 if(this.el.dom.checked != this.checked){
150 this.setValue(this.el.dom.checked);
154 <div id="method-Ext.form.Checkbox-setValue"></div>/**
155 * Sets the checked state of the checkbox, fires the 'check' event, and calls a
156 * <code>{@link #handler}</code> (if configured).
157 * @param {Boolean/String} checked The following values will check the checkbox:
158 * <code>true, 'true', '1', or 'on'</code>. Any other value will uncheck the checkbox.
159 * @return {Ext.form.Field} this
161 setValue : function(v){
162 var checked = this.checked ;
163 this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
165 this.el.dom.checked = this.checked;
166 this.el.dom.defaultChecked = this.checked;
168 if(checked != this.checked){
169 this.fireEvent('check', this, this.checked);
171 this.handler.call(this.scope || this, this, this.checked);
177 Ext.reg('checkbox', Ext.form.Checkbox);