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.TriggerField"></div>/**
9 * @class Ext.form.TriggerField
10 * @extends Ext.form.TextField
11 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
12 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
13 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
14 * for which you can provide a custom implementation. For example:
16 var trigger = new Ext.form.TriggerField();
17 trigger.onTriggerClick = myTriggerFn;
18 trigger.applyToMarkup('my-field');
21 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
22 * {@link Ext.form.DateField} and {@link Ext.form.ComboBox} are perfect examples of this.
25 * Create a new TriggerField.
26 * @param {Object} config Configuration options (valid {@Ext.form.TextField} config options will also be applied
27 * to the base TextField)
30 Ext.form.TriggerField = Ext.extend(Ext.form.TextField, {
31 <div id="cfg-Ext.form.TriggerField-triggerClass"></div>/**
32 * @cfg {String} triggerClass
33 * An additional CSS class used to style the trigger button. The trigger will always get the
34 * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
36 <div id="cfg-Ext.form.TriggerField-triggerConfig"></div>/**
37 * @cfg {Mixed} triggerConfig
38 * <p>A {@link Ext.DomHelper DomHelper} config object specifying the structure of the
39 * trigger element for this Field. (Optional).</p>
40 * <p>Specify this when you need a customized element to act as the trigger button for a TriggerField.</p>
41 * <p>Note that when using this option, it is the developer's responsibility to ensure correct sizing, positioning
42 * and appearance of the trigger. Defaults to:</p>
43 * <pre><code>{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass}</code></pre>
45 <div id="cfg-Ext.form.TriggerField-autoCreate"></div>/**
46 * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
47 * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
48 * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
49 * <pre><code>{tag: "input", type: "text", size: "16", autocomplete: "off"}</code></pre>
51 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
52 <div id="cfg-Ext.form.TriggerField-hideTrigger"></div>/**
53 * @cfg {Boolean} hideTrigger <tt>true</tt> to hide the trigger element and display only the base
54 * text field (defaults to <tt>false</tt>)
57 <div id="cfg-Ext.form.TriggerField-editable"></div>/**
58 * @cfg {Boolean} editable <tt>false</tt> to prevent the user from typing text directly into the field,
59 * the field will only respond to a click on the trigger to set the value. (defaults to <tt>true</tt>)
62 <div id="cfg-Ext.form.TriggerField-wrapFocusClass"></div>/**
63 * @cfg {String} wrapFocusClass The class added to the to the wrap of the trigger element. Defaults to
64 * <tt>x-trigger-wrap-focus</tt>.
66 wrapFocusClass: 'x-trigger-wrap-focus',
67 <div id="method-Ext.form.TriggerField-autoSize"></div>/**
71 autoSize: Ext.emptyFn,
82 onResize : function(w, h){
83 Ext.form.TriggerField.superclass.onResize.call(this, w, h);
84 if(typeof w == 'number'){
85 this.el.setWidth(this.adjustWidth('input', w - this.trigger.getWidth()));
87 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
91 adjustSize : Ext.BoxComponent.prototype.adjustSize,
94 getResizeEl : function(){
99 getPositionEl : function(){
104 alignErrorIcon : function(){
106 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
111 onRender : function(ct, position){
112 Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
114 this.wrap = this.el.wrap({cls: 'x-form-field-wrap x-form-field-trigger-wrap'});
115 this.trigger = this.wrap.createChild(this.triggerConfig ||
116 {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
117 if(this.hideTrigger){
118 this.trigger.setDisplayed(false);
122 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
125 this.editable = true;
126 this.setEditable(false);
130 afterRender : function(){
131 Ext.form.TriggerField.superclass.afterRender.call(this);
135 initTrigger : function(){
136 this.mon(this.trigger, 'click', this.onTriggerClick, this, {preventDefault:true});
137 this.trigger.addClassOnOver('x-form-trigger-over');
138 this.trigger.addClassOnClick('x-form-trigger-click');
142 onDestroy : function(){
143 Ext.destroy(this.trigger, this.wrap);
145 Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
147 Ext.form.TriggerField.superclass.onDestroy.call(this);
151 onFocus : function(){
152 Ext.form.TriggerField.superclass.onFocus.call(this);
154 this.wrap.addClass(this.wrapFocusClass);
155 this.mimicing = true;
156 Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {delay: 10});
158 this.el.on('keydown', this.checkTab, this);
164 checkTab : function(e){
165 if(e.getKey() == e.TAB){
176 mimicBlur : function(e){
177 if(!this.wrap.contains(e.target) && this.validateBlur(e)){
183 triggerBlur : function(){
184 this.mimicing = false;
185 Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
186 if(this.monitorTab && this.el){
187 this.el.un("keydown", this.checkTab, this);
189 Ext.form.TriggerField.superclass.onBlur.call(this);
191 this.wrap.removeClass(this.wrapFocusClass);
195 beforeBlur : Ext.emptyFn,
197 <div id="method-Ext.form.TriggerField-setEditable"></div>/**
198 * Allow or prevent the user from directly editing the field text. If false is passed,
199 * the user will only be able to modify the field using the trigger. This method
200 * is the runtime equivalent of setting the 'editable' config option at config time.
201 * @param {Boolean} value True to allow the user to directly edit the field text
203 setEditable : function(value){
204 if(value == this.editable){
207 this.editable = value;
209 this.el.addClass('x-trigger-noedit').on('click', this.onTriggerClick, this).dom.setAttribute('readOnly', true);
211 this.el.removeClass('x-trigger-noedit').un('click', this.onTriggerClick, this).dom.removeAttribute('readOnly');
216 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
217 validateBlur : function(e){
221 <div id="method-Ext.form.TriggerField-onTriggerClick"></div>/**
222 * The function that should handle the trigger's click event. This method does nothing by default
223 * until overridden by an implementing function. See Ext.form.ComboBox and Ext.form.DateField for
224 * sample implementations.
226 * @param {EventObject} e
228 onTriggerClick : Ext.emptyFn
230 <div id="cfg-Ext.form.TriggerField-grow"></div>/**
231 * @cfg {Boolean} grow @hide
233 <div id="cfg-Ext.form.TriggerField-growMin"></div>/**
234 * @cfg {Number} growMin @hide
236 <div id="cfg-Ext.form.TriggerField-growMax"></div>/**
237 * @cfg {Number} growMax @hide
241 <div id="cls-Ext.form.TwinTriggerField"></div>/**
242 * @class Ext.form.TwinTriggerField
243 * @extends Ext.form.TriggerField
244 * TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
245 * to be extended by an implementing class. For an example of implementing this class, see the custom
246 * SearchField implementation here:
247 * <a href="http://extjs.com/deploy/ext/examples/form/custom.html">http://extjs.com/deploy/ext/examples/form/custom.html</a>
249 Ext.form.TwinTriggerField = Ext.extend(Ext.form.TriggerField, {
250 <div id="cfg-Ext.form.TwinTriggerField-triggerConfig"></div>/**
251 * @cfg {Mixed} triggerConfig
252 * <p>A {@link Ext.DomHelper DomHelper} config object specifying the structure of the trigger elements
253 * for this Field. (Optional).</p>
254 * <p>Specify this when you need a customized element to contain the two trigger elements for this Field.
255 * Each trigger element must be marked by the CSS class <tt>x-form-trigger</tt> (also see
256 * <tt>{@link #trigger1Class}</tt> and <tt>{@link #trigger2Class}</tt>).</p>
257 * <p>Note that when using this option, it is the developer's responsibility to ensure correct sizing,
258 * positioning and appearance of the triggers.</p>
260 <div id="cfg-Ext.form.TwinTriggerField-trigger1Class"></div>/**
261 * @cfg {String} trigger1Class
262 * An additional CSS class used to style the trigger button. The trigger will always get the
263 * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
265 <div id="cfg-Ext.form.TwinTriggerField-trigger2Class"></div>/**
266 * @cfg {String} trigger2Class
267 * An additional CSS class used to style the trigger button. The trigger will always get the
268 * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
271 initComponent : function(){
272 Ext.form.TwinTriggerField.superclass.initComponent.call(this);
274 this.triggerConfig = {
275 tag:'span', cls:'x-form-twin-triggers', cn:[
276 {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
277 {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
281 getTrigger : function(index){
282 return this.triggers[index];
285 initTrigger : function(){
286 var ts = this.trigger.select('.x-form-trigger', true);
287 this.wrap.setStyle('overflow', 'hidden');
288 var triggerField = this;
289 ts.each(function(t, all, index){
291 var w = triggerField.wrap.getWidth();
292 this.dom.style.display = 'none';
293 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
296 var w = triggerField.wrap.getWidth();
297 this.dom.style.display = '';
298 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
300 var triggerIndex = 'Trigger'+(index+1);
302 if(this['hide'+triggerIndex]){
303 t.dom.style.display = 'none';
305 this.mon(t, 'click', this['on'+triggerIndex+'Click'], this, {preventDefault:true});
306 t.addClassOnOver('x-form-trigger-over');
307 t.addClassOnClick('x-form-trigger-click');
309 this.triggers = ts.elements;
312 <div id="method-Ext.form.TwinTriggerField-onTrigger1Click"></div>/**
313 * The function that should handle the trigger's click event. This method does nothing by default
314 * until overridden by an implementing function. See {@link Ext.form.TriggerField#onTriggerClick}
315 * for additional information.
317 * @param {EventObject} e
319 onTrigger1Click : Ext.emptyFn,
320 <div id="method-Ext.form.TwinTriggerField-onTrigger2Click"></div>/**
321 * The function that should handle the trigger's click event. This method does nothing by default
322 * until overridden by an implementing function. See {@link Ext.form.TriggerField#onTriggerClick}
323 * for additional information.
325 * @param {EventObject} e
327 onTrigger2Click : Ext.emptyFn
329 Ext.reg('trigger', Ext.form.TriggerField);</pre>
\r