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.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.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-inputValue"></div>/**
47 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
49 <div id="cfg-Ext.form.Checkbox-handler"></div>/**
50 * @cfg {Function} handler A function called when the {@link #checked} value changes (can be used instead of
51 * handling the check event). The handler is passed the following parameters:
52 * <div class="mdetail-params"><ul>
53 * <li><b>checkbox</b> : Ext.form.Checkbox<div class="sub-desc">The Checkbox being toggled.</div></li>
54 * <li><b>checked</b> : Boolean<div class="sub-desc">The new checked state of the checkbox.</div></li>
57 <div id="cfg-Ext.form.Checkbox-scope"></div>/**
58 * @cfg {Object} scope An object to use as the scope ('this' reference) of the {@link #handler} function
59 * (defaults to this Checkbox).
66 initComponent : function(){
67 Ext.form.Checkbox.superclass.initComponent.call(this);
69 <div id="event-Ext.form.Checkbox-check"></div>/**
71 * Fires when the checkbox is checked or unchecked.
72 * @param {Ext.form.Checkbox} this This checkbox
73 * @param {Boolean} checked The new checked value
80 onResize : function(){
81 Ext.form.Checkbox.superclass.onResize.apply(this, arguments);
82 if(!this.boxLabel && !this.fieldLabel){
83 this.el.alignTo(this.wrap, 'c-c');
88 initEvents : function(){
89 Ext.form.Checkbox.superclass.initEvents.call(this);
97 <div id="method-Ext.form.Checkbox-markInvalid"></div>/**
99 * Overridden and disabled. The editor element does not support standard valid/invalid marking.
102 markInvalid : Ext.emptyFn,
103 <div id="method-Ext.form.Checkbox-clearInvalid"></div>/**
105 * Overridden and disabled. The editor element does not support standard valid/invalid marking.
108 clearInvalid : Ext.emptyFn,
111 onRender : function(ct, position){
112 Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
113 if(this.inputValue !== undefined){
114 this.el.dom.value = this.inputValue;
116 this.wrap = this.el.wrap({cls: 'x-form-check-wrap'});
118 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
123 this.checked = this.el.dom.checked;
125 // Need to repaint for IE, otherwise positioning is broken
126 if (Ext.isIE && !Ext.isStrict) {
129 this.resizeEl = this.positionEl = this.wrap;
133 onDestroy : function(){
134 Ext.destroy(this.wrap);
135 Ext.form.Checkbox.superclass.onDestroy.call(this);
139 initValue : function() {
140 this.originalValue = this.getValue();
143 <div id="method-Ext.form.Checkbox-getValue"></div>/**
144 * Returns the checked state of the checkbox.
145 * @return {Boolean} True if checked, else false
147 getValue : function(){
149 return this.el.dom.checked;
155 onClick : function(){
156 if(this.el.dom.checked != this.checked){
157 this.setValue(this.el.dom.checked);
161 <div id="method-Ext.form.Checkbox-setValue"></div>/**
162 * Sets the checked state of the checkbox, fires the 'check' event, and calls a
163 * <code>{@link #handler}</code> (if configured).
164 * @param {Boolean/String} checked The following values will check the checkbox:
165 * <code>true, 'true', '1', or 'on'</code>. Any other value will uncheck the checkbox.
166 * @return {Ext.form.Field} this
168 setValue : function(v){
169 var checked = this.checked,
170 inputVal = this.inputValue;
172 this.checked = (v === true || v === 'true' || v == '1' || (inputVal ? v == inputVal : String(v).toLowerCase() == 'on'));
174 this.el.dom.checked = this.checked;
175 this.el.dom.defaultChecked = this.checked;
177 if(checked != this.checked){
178 this.fireEvent('check', this, this.checked);
180 this.handler.call(this.scope || this, this, this.checked);
186 Ext.reg('checkbox', Ext.form.Checkbox);