3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.2
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.form.Checkbox"></div>/**
16 * @class Ext.form.Checkbox
17 * @extends Ext.form.Field
18 * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
20 * Creates a new Checkbox
21 * @param {Object} config Configuration options
24 Ext.form.Checkbox = Ext.extend(Ext.form.Field, {
25 <div id="cfg-Ext.form.Checkbox-focusClass"></div>/**
26 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
28 focusClass : undefined,
29 <div id="cfg-Ext.form.Checkbox-fieldClass"></div>/**
30 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to 'x-form-field')
32 fieldClass : 'x-form-field',
33 <div id="cfg-Ext.form.Checkbox-checked"></div>/**
34 * @cfg {Boolean} checked <tt>true</tt> if the checkbox should render initially checked (defaults to <tt>false</tt>)
37 <div id="cfg-Ext.form.Checkbox-boxLabel"></div>/**
38 * @cfg {String} boxLabel The text that appears beside the checkbox
41 <div id="cfg-Ext.form.Checkbox-autoCreate"></div>/**
42 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
43 * {tag: 'input', type: 'checkbox', autocomplete: 'off'})
45 defaultAutoCreate : { tag: 'input', type: 'checkbox', autocomplete: 'off'},
46 <div id="cfg-Ext.form.Checkbox-boxLabel"></div>/**
47 * @cfg {String} boxLabel The text that appears beside the checkbox
49 <div id="cfg-Ext.form.Checkbox-inputValue"></div>/**
50 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
52 <div id="cfg-Ext.form.Checkbox-handler"></div>/**
53 * @cfg {Function} handler A function called when the {@link #checked} value changes (can be used instead of
54 * handling the check event). The handler is passed the following parameters:
55 * <div class="mdetail-params"><ul>
56 * <li><b>checkbox</b> : Ext.form.Checkbox<div class="sub-desc">The Checkbox being toggled.</div></li>
57 * <li><b>checked</b> : Boolean<div class="sub-desc">The new checked state of the checkbox.</div></li>
60 <div id="cfg-Ext.form.Checkbox-scope"></div>/**
61 * @cfg {Object} scope An object to use as the scope ('this' reference) of the {@link #handler} function
62 * (defaults to this Checkbox).
69 initComponent : function(){
70 Ext.form.Checkbox.superclass.initComponent.call(this);
72 <div id="event-Ext.form.Checkbox-check"></div>/**
74 * Fires when the checkbox is checked or unchecked.
75 * @param {Ext.form.Checkbox} this This checkbox
76 * @param {Boolean} checked The new checked value
83 onResize : function(){
84 Ext.form.Checkbox.superclass.onResize.apply(this, arguments);
85 if(!this.boxLabel && !this.fieldLabel){
86 this.el.alignTo(this.wrap, 'c-c');
91 initEvents : function(){
92 Ext.form.Checkbox.superclass.initEvents.call(this);
100 <div id="method-Ext.form.Checkbox-markInvalid"></div>/**
102 * Overridden and disabled. The editor element does not support standard valid/invalid marking.
105 markInvalid : Ext.emptyFn,
106 <div id="method-Ext.form.Checkbox-clearInvalid"></div>/**
108 * Overridden and disabled. The editor element does not support standard valid/invalid marking.
111 clearInvalid : Ext.emptyFn,
114 onRender : function(ct, position){
115 Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
116 if(this.inputValue !== undefined){
117 this.el.dom.value = this.inputValue;
119 this.wrap = this.el.wrap({cls: 'x-form-check-wrap'});
121 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
126 this.checked = this.el.dom.checked;
128 // Need to repaint for IE, otherwise positioning is broken
129 if (Ext.isIE && !Ext.isStrict) {
132 this.resizeEl = this.positionEl = this.wrap;
136 onDestroy : function(){
137 Ext.destroy(this.wrap);
138 Ext.form.Checkbox.superclass.onDestroy.call(this);
142 initValue : function() {
143 this.originalValue = this.getValue();
146 <div id="method-Ext.form.Checkbox-getValue"></div>/**
147 * Returns the checked state of the checkbox.
148 * @return {Boolean} True if checked, else false
150 getValue : function(){
152 return this.el.dom.checked;
158 onClick : function(){
159 if(this.el.dom.checked != this.checked){
160 this.setValue(this.el.dom.checked);
164 <div id="method-Ext.form.Checkbox-setValue"></div>/**
165 * Sets the checked state of the checkbox, fires the 'check' event, and calls a
166 * <code>{@link #handler}</code> (if configured).
167 * @param {Boolean/String} checked The following values will check the checkbox:
168 * <code>true, 'true', '1', or 'on'</code>. Any other value will uncheck the checkbox.
169 * @return {Ext.form.Field} this
171 setValue : function(v){
172 var checked = this.checked ;
173 this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
175 this.el.dom.checked = this.checked;
176 this.el.dom.defaultChecked = this.checked;
178 if(checked != this.checked){
179 this.fireEvent('check', this, this.checked);
181 this.handler.call(this.scope || this, this, this.checked);
187 Ext.reg('checkbox', Ext.form.Checkbox);