3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.form.Checkbox"></div>/**
9 * @class Ext.form.Checkbox
10 * @extends Ext.form.Field
11 * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
13 * Creates a new Checkbox
14 * @param {Object} config Configuration options
17 Ext.form.Checkbox = Ext.extend(Ext.form.Field, {
18 <div id="cfg-Ext.form.Checkbox-focusClass"></div>/**
19 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
21 focusClass : undefined,
22 <div id="cfg-Ext.form.Checkbox-fieldClass"></div>/**
23 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to 'x-form-field')
25 fieldClass : 'x-form-field',
26 <div id="cfg-Ext.form.Checkbox-checked"></div>/**
27 * @cfg {Boolean} checked <tt>true</tt> if the checkbox should render initially checked (defaults to <tt>false</tt>)
30 <div id="cfg-Ext.form.Checkbox-autoCreate"></div>/**
31 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
32 * {tag: 'input', type: 'checkbox', autocomplete: 'off'})
34 defaultAutoCreate : { tag: 'input', type: 'checkbox', autocomplete: 'off'},
35 <div id="cfg-Ext.form.Checkbox-boxLabel"></div>/**
36 * @cfg {String} boxLabel The text that appears beside the checkbox
38 <div id="cfg-Ext.form.Checkbox-inputValue"></div>/**
39 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
41 <div id="cfg-Ext.form.Checkbox-handler"></div>/**
42 * @cfg {Function} handler A function called when the {@link #checked} value changes (can be used instead of
43 * handling the check event). The handler is passed the following parameters:
44 * <div class="mdetail-params"><ul>
45 * <li><b>checkbox</b> : Ext.form.Checkbox<div class="sub-desc">The Checkbox being toggled.</div></li>
46 * <li><b>checked</b> : Boolean<div class="sub-desc">The new checked state of the checkbox.</div></li>
49 <div id="cfg-Ext.form.Checkbox-scope"></div>/**
50 * @cfg {Object} scope An object to use as the scope ('this' reference) of the {@link #handler} function
51 * (defaults to this Checkbox).
58 initComponent : function(){
59 Ext.form.Checkbox.superclass.initComponent.call(this);
61 <div id="event-Ext.form.Checkbox-check"></div>/**
63 * Fires when the checkbox is checked or unchecked.
64 * @param {Ext.form.Checkbox} this This checkbox
65 * @param {Boolean} checked The new checked value
72 onResize : function(){
73 Ext.form.Checkbox.superclass.onResize.apply(this, arguments);
74 if(!this.boxLabel && !this.fieldLabel){
75 this.el.alignTo(this.wrap, 'c-c');
80 initEvents : function(){
81 Ext.form.Checkbox.superclass.initEvents.call(this);
82 this.mon(this.el, 'click', this.onClick, this);
83 this.mon(this.el, 'change', this.onClick, this);
87 getResizeEl : function(){
92 getPositionEl : function(){
96 <div id="method-Ext.form.Checkbox-markInvalid"></div>/**
98 * Overridden and disabled. The editor element does not support standard valid/invalid marking.
101 markInvalid : Ext.emptyFn,
102 <div id="method-Ext.form.Checkbox-clearInvalid"></div>/**
104 * Overridden and disabled. The editor element does not support standard valid/invalid marking.
107 clearInvalid : Ext.emptyFn,
110 onRender : function(ct, position){
111 Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
112 if(this.inputValue !== undefined){
113 this.el.dom.value = this.inputValue;
115 this.wrap = this.el.wrap({cls: 'x-form-check-wrap'});
117 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
122 this.checked = this.el.dom.checked;
127 onDestroy : function(){
128 Ext.destroy(this.wrap);
129 Ext.form.Checkbox.superclass.onDestroy.call(this);
133 initValue : function() {
134 this.originalValue = this.getValue();
137 <div id="method-Ext.form.Checkbox-getValue"></div>/**
138 * Returns the checked state of the checkbox.
139 * @return {Boolean} True if checked, else false
141 getValue : function(){
143 return this.el.dom.checked;
149 onClick : function(){
150 if(this.el.dom.checked != this.checked){
151 this.setValue(this.el.dom.checked);
155 <div id="method-Ext.form.Checkbox-setValue"></div>/**
156 * Sets the checked state of the checkbox, fires the 'check' event, and calls a
157 * <code>{@link #handler}</code> (if configured).
158 * @param {Boolean/String} checked The following values will check the checkbox:
159 * <code>true, 'true', '1', or 'on'</code>. Any other value will uncheck the checkbox.
160 * @return {Ext.form.Field} this
162 setValue : function(v){
163 var checked = this.checked ;
164 this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
166 this.el.dom.checked = this.checked;
167 this.el.dom.defaultChecked = this.checked;
169 if(checked != this.checked){
170 this.fireEvent('check', this, this.checked);
172 this.handler.call(this.scope || this, this, this.checked);
178 Ext.reg('checkbox', Ext.form.Checkbox);