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.TriggerField"></div>/**
16 * @class Ext.form.TriggerField
17 * @extends Ext.form.TextField
18 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
19 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
20 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
21 * for which you can provide a custom implementation. For example:
23 var trigger = new Ext.form.TriggerField();
24 trigger.onTriggerClick = myTriggerFn;
25 trigger.applyToMarkup('my-field');
28 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
29 * {@link Ext.form.DateField} and {@link Ext.form.ComboBox} are perfect examples of this.
32 * Create a new TriggerField.
33 * @param {Object} config Configuration options (valid {@Ext.form.TextField} config options will also be applied
34 * to the base TextField)
37 Ext.form.TriggerField = Ext.extend(Ext.form.TextField, {
38 <div id="cfg-Ext.form.TriggerField-triggerClass"></div>/**
39 * @cfg {String} triggerClass
40 * An additional CSS class used to style the trigger button. The trigger will always get the
41 * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
43 <div id="cfg-Ext.form.TriggerField-triggerConfig"></div>/**
44 * @cfg {Mixed} triggerConfig
45 * <p>A {@link Ext.DomHelper DomHelper} config object specifying the structure of the
46 * trigger element for this Field. (Optional).</p>
47 * <p>Specify this when you need a customized element to act as the trigger button for a TriggerField.</p>
48 * <p>Note that when using this option, it is the developer's responsibility to ensure correct sizing, positioning
49 * and appearance of the trigger. Defaults to:</p>
50 * <pre><code>{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass}</code></pre>
52 <div id="cfg-Ext.form.TriggerField-autoCreate"></div>/**
53 * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
54 * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
55 * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
56 * <pre><code>{tag: "input", type: "text", size: "16", autocomplete: "off"}</code></pre>
58 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
59 <div id="cfg-Ext.form.TriggerField-hideTrigger"></div>/**
60 * @cfg {Boolean} hideTrigger <tt>true</tt> to hide the trigger element and display only the base
61 * text field (defaults to <tt>false</tt>)
64 <div id="cfg-Ext.form.TriggerField-editable"></div>/**
65 * @cfg {Boolean} editable <tt>false</tt> to prevent the user from typing text directly into the field,
66 * the field will only respond to a click on the trigger to set the value. (defaults to <tt>true</tt>).
69 <div id="cfg-Ext.form.TriggerField-readOnly"></div>/**
70 * @cfg {Boolean} readOnly <tt>true</tt> to prevent the user from changing the field, and
71 * hides the trigger. Superceeds the editable and hideTrigger options if the value is true.
72 * (defaults to <tt>false</tt>)
75 <div id="cfg-Ext.form.TriggerField-wrapFocusClass"></div>/**
76 * @cfg {String} wrapFocusClass The class added to the to the wrap of the trigger element. Defaults to
77 * <tt>x-trigger-wrap-focus</tt>.
79 wrapFocusClass: 'x-trigger-wrap-focus',
80 <div id="method-Ext.form.TriggerField-autoSize"></div>/**
84 autoSize: Ext.emptyFn,
94 defaultTriggerWidth: 17,
97 onResize : function(w, h){
98 Ext.form.TriggerField.superclass.onResize.call(this, w, h);
99 var tw = this.getTriggerWidth();
101 this.el.setWidth(w - tw);
103 this.wrap.setWidth(this.el.getWidth() + tw);
106 getTriggerWidth: function(){
107 var tw = this.trigger.getWidth();
108 if(!this.hideTrigger && !this.readOnly && tw === 0){
109 tw = this.defaultTriggerWidth;
115 alignErrorIcon : function(){
117 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
122 onRender : function(ct, position){
123 this.doc = Ext.isIE ? Ext.getBody() : Ext.getDoc();
124 Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
126 this.wrap = this.el.wrap({cls: 'x-form-field-wrap x-form-field-trigger-wrap'});
127 this.trigger = this.wrap.createChild(this.triggerConfig ||
128 {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.triggerClass});
131 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
133 this.resizeEl = this.positionEl = this.wrap;
136 getWidth: function() {
137 return(this.el.getWidth() + this.trigger.getWidth());
140 updateEditState: function(){
143 this.el.dom.readOnly = true;
144 this.el.addClass('x-trigger-noedit');
145 this.mun(this.el, 'click', this.onTriggerClick, this);
146 this.trigger.setDisplayed(false);
148 if (!this.editable) {
149 this.el.dom.readOnly = true;
150 this.el.addClass('x-trigger-noedit');
151 this.mon(this.el, 'click', this.onTriggerClick, this);
153 this.el.dom.readOnly = false;
154 this.el.removeClass('x-trigger-noedit');
155 this.mun(this.el, 'click', this.onTriggerClick, this);
157 this.trigger.setDisplayed(!this.hideTrigger);
159 this.onResize(this.width || this.wrap.getWidth());
163 <div id="method-Ext.form.TriggerField-setHideTrigger"></div>/**
164 * Changes the hidden status of the trigger.
165 * @param {Boolean} hideTrigger True to hide the trigger, false to show it.
167 setHideTrigger: function(hideTrigger){
168 if(hideTrigger != this.hideTrigger){
169 this.hideTrigger = hideTrigger;
170 this.updateEditState();
174 <div id="method-Ext.form.TriggerField-setEditable"></div>/**
175 * Allow or prevent the user from directly editing the field text. If false is passed,
176 * the user will only be able to modify the field using the trigger. Will also add
177 * a click event to the text field which will call the trigger. This method
178 * is the runtime equivalent of setting the {@link #editable} config option at config time.
179 * @param {Boolean} value True to allow the user to directly edit the field text.
181 setEditable: function(editable){
182 if(editable != this.editable){
183 this.editable = editable;
184 this.updateEditState();
188 <div id="method-Ext.form.TriggerField-setReadOnly"></div>/**
189 * Setting this to true will supersede settings {@link #editable} and {@link #hideTrigger}.
190 * Setting this to false will defer back to {@link #editable} and {@link #hideTrigger}. This method
191 * is the runtime equivalent of setting the {@link #readOnly} config option at config time.
192 * @param {Boolean} value True to prevent the user changing the field and explicitly
195 setReadOnly: function(readOnly){
196 if(readOnly != this.readOnly){
197 this.readOnly = readOnly;
198 this.updateEditState();
202 afterRender : function(){
203 Ext.form.TriggerField.superclass.afterRender.call(this);
204 this.updateEditState();
208 initTrigger : function(){
209 this.mon(this.trigger, 'click', this.onTriggerClick, this, {preventDefault:true});
210 this.trigger.addClassOnOver('x-form-trigger-over');
211 this.trigger.addClassOnClick('x-form-trigger-click');
215 onDestroy : function(){
216 Ext.destroy(this.trigger, this.wrap);
218 this.doc.un('mousedown', this.mimicBlur, this);
221 Ext.form.TriggerField.superclass.onDestroy.call(this);
225 onFocus : function(){
226 Ext.form.TriggerField.superclass.onFocus.call(this);
228 this.wrap.addClass(this.wrapFocusClass);
229 this.mimicing = true;
230 this.doc.on('mousedown', this.mimicBlur, this, {delay: 10});
232 this.on('specialkey', this.checkTab, this);
238 checkTab : function(me, e){
239 if(e.getKey() == e.TAB){
245 onBlur : Ext.emptyFn,
248 mimicBlur : function(e){
249 if(!this.isDestroyed && !this.wrap.contains(e.target) && this.validateBlur(e)){
255 triggerBlur : function(){
256 this.mimicing = false;
257 this.doc.un('mousedown', this.mimicBlur, this);
258 if(this.monitorTab && this.el){
259 this.un('specialkey', this.checkTab, this);
261 Ext.form.TriggerField.superclass.onBlur.call(this);
263 this.wrap.removeClass(this.wrapFocusClass);
267 beforeBlur : Ext.emptyFn,
270 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
271 validateBlur : function(e){
275 <div id="method-Ext.form.TriggerField-onTriggerClick"></div>/**
276 * The function that should handle the trigger's click event. This method does nothing by default
277 * until overridden by an implementing function. See Ext.form.ComboBox and Ext.form.DateField for
278 * sample implementations.
280 * @param {EventObject} e
282 onTriggerClick : Ext.emptyFn
284 <div id="cfg-Ext.form.TriggerField-grow"></div>/**
285 * @cfg {Boolean} grow @hide
287 <div id="cfg-Ext.form.TriggerField-growMin"></div>/**
288 * @cfg {Number} growMin @hide
290 <div id="cfg-Ext.form.TriggerField-growMax"></div>/**
291 * @cfg {Number} growMax @hide
295 <div id="cls-Ext.form.TwinTriggerField"></div>/**
296 * @class Ext.form.TwinTriggerField
297 * @extends Ext.form.TriggerField
298 * TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
299 * to be extended by an implementing class. For an example of implementing this class, see the custom
300 * SearchField implementation here:
301 * <a href="http://extjs.com/deploy/ext/examples/form/custom.html">http://extjs.com/deploy/ext/examples/form/custom.html</a>
303 Ext.form.TwinTriggerField = Ext.extend(Ext.form.TriggerField, {
304 <div id="cfg-Ext.form.TwinTriggerField-triggerConfig"></div>/**
305 * @cfg {Mixed} triggerConfig
306 * <p>A {@link Ext.DomHelper DomHelper} config object specifying the structure of the trigger elements
307 * for this Field. (Optional).</p>
308 * <p>Specify this when you need a customized element to contain the two trigger elements for this Field.
309 * Each trigger element must be marked by the CSS class <tt>x-form-trigger</tt> (also see
310 * <tt>{@link #trigger1Class}</tt> and <tt>{@link #trigger2Class}</tt>).</p>
311 * <p>Note that when using this option, it is the developer's responsibility to ensure correct sizing,
312 * positioning and appearance of the triggers.</p>
314 <div id="cfg-Ext.form.TwinTriggerField-trigger1Class"></div>/**
315 * @cfg {String} trigger1Class
316 * An additional CSS class used to style the trigger button. The trigger will always get the
317 * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
319 <div id="cfg-Ext.form.TwinTriggerField-trigger2Class"></div>/**
320 * @cfg {String} trigger2Class
321 * An additional CSS class used to style the trigger button. The trigger will always get the
322 * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
325 initComponent : function(){
326 Ext.form.TwinTriggerField.superclass.initComponent.call(this);
328 this.triggerConfig = {
329 tag:'span', cls:'x-form-twin-triggers', cn:[
330 {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.trigger1Class},
331 {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.trigger2Class}
335 getTrigger : function(index){
336 return this.triggers[index];
339 afterRender: function(){
340 Ext.form.TwinTriggerField.superclass.afterRender.call(this);
341 var triggers = this.triggers,
343 len = triggers.length;
346 if(this['hideTrigger' + (i + 1)]){
353 initTrigger : function(){
354 var ts = this.trigger.select('.x-form-trigger', true),
357 ts.each(function(t, all, index){
358 var triggerIndex = 'Trigger'+(index+1);
360 var w = triggerField.wrap.getWidth();
361 this.dom.style.display = 'none';
362 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
363 triggerField['hidden' + triggerIndex] = true;
366 var w = triggerField.wrap.getWidth();
367 this.dom.style.display = '';
368 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
369 triggerField['hidden' + triggerIndex] = false;
371 this.mon(t, 'click', this['on'+triggerIndex+'Click'], this, {preventDefault:true});
372 t.addClassOnOver('x-form-trigger-over');
373 t.addClassOnClick('x-form-trigger-click');
375 this.triggers = ts.elements;
378 getTriggerWidth: function(){
380 Ext.each(this.triggers, function(t, index){
381 var triggerIndex = 'Trigger' + (index + 1),
383 if(w === 0 && !this['hidden' + triggerIndex]){
384 tw += this.defaultTriggerWidth;
393 onDestroy : function() {
394 Ext.destroy(this.triggers);
395 Ext.form.TwinTriggerField.superclass.onDestroy.call(this);
398 <div id="method-Ext.form.TwinTriggerField-onTrigger1Click"></div>/**
399 * The function that should handle the trigger's click event. This method does nothing by default
400 * until overridden by an implementing function. See {@link Ext.form.TriggerField#onTriggerClick}
401 * for additional information.
403 * @param {EventObject} e
405 onTrigger1Click : Ext.emptyFn,
406 <div id="method-Ext.form.TwinTriggerField-onTrigger2Click"></div>/**
407 * The function that should handle the trigger's click event. This method does nothing by default
408 * until overridden by an implementing function. See {@link Ext.form.TriggerField#onTriggerClick}
409 * for additional information.
411 * @param {EventObject} e
413 onTrigger2Click : Ext.emptyFn
415 Ext.reg('trigger', Ext.form.TriggerField);