2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.form.TriggerField
\r
11 * @extends Ext.form.TextField
\r
12 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
\r
13 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
\r
14 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
\r
15 * for which you can provide a custom implementation. For example:
\r
17 var trigger = new Ext.form.TriggerField();
\r
18 trigger.onTriggerClick = myTriggerFn;
\r
19 trigger.applyToMarkup('my-field');
\r
22 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
\r
23 * {@link Ext.form.DateField} and {@link Ext.form.ComboBox} are perfect examples of this.
\r
24 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
\r
25 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
\r
27 * Create a new TriggerField.
\r
28 * @param {Object} config Configuration options (valid {@Ext.form.TextField} config options will also be applied
\r
29 * to the base TextField)
\r
31 Ext.form.TriggerField = Ext.extend(Ext.form.TextField, {
\r
33 * @cfg {String} triggerClass A CSS class to apply to the trigger
\r
36 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
\r
37 * {tag: "input", type: "text", size: "16", autocomplete: "off"})
\r
39 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
\r
41 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
\r
49 autoSize: Ext.emptyFn,
\r
58 onResize : function(w, h){
\r
59 Ext.form.TriggerField.superclass.onResize.call(this, w, h);
\r
60 if(typeof w == 'number'){
\r
61 this.el.setWidth(this.adjustWidth('input', w - this.trigger.getWidth()));
\r
63 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
\r
67 adjustSize : Ext.BoxComponent.prototype.adjustSize,
\r
70 getResizeEl : function(){
\r
75 getPositionEl : function(){
\r
80 alignErrorIcon : function(){
\r
82 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
\r
87 onRender : function(ct, position){
\r
88 Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
\r
89 this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
\r
90 this.trigger = this.wrap.createChild(this.triggerConfig ||
\r
91 {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
\r
92 if(this.hideTrigger){
\r
93 this.trigger.setDisplayed(false);
\r
97 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
\r
101 afterRender : function(){
\r
102 Ext.form.TriggerField.superclass.afterRender.call(this);
\r
104 if(Ext.isIE && !this.hideTrigger && this.el.getY() != (y = this.trigger.getY())){
\r
105 this.el.position();
\r
111 initTrigger : function(){
\r
112 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
\r
113 this.trigger.addClassOnOver('x-form-trigger-over');
\r
114 this.trigger.addClassOnClick('x-form-trigger-click');
\r
118 onDestroy : function(){
\r
120 this.trigger.removeAllListeners();
\r
121 this.trigger.remove();
\r
124 this.wrap.remove();
\r
126 Ext.form.TriggerField.superclass.onDestroy.call(this);
\r
130 onFocus : function(){
\r
131 Ext.form.TriggerField.superclass.onFocus.call(this);
\r
132 if(!this.mimicing){
\r
133 this.wrap.addClass('x-trigger-wrap-focus');
\r
134 this.mimicing = true;
\r
135 Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {delay: 10});
\r
136 if(this.monitorTab){
\r
137 this.el.on("keydown", this.checkTab, this);
\r
143 checkTab : function(e){
\r
144 if(e.getKey() == e.TAB){
\r
145 this.triggerBlur();
\r
150 onBlur : function(){
\r
155 mimicBlur : function(e){
\r
156 if(!this.wrap.contains(e.target) && this.validateBlur(e)){
\r
157 this.triggerBlur();
\r
162 triggerBlur : function(){
\r
163 this.mimicing = false;
\r
164 Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
\r
165 if(this.monitorTab && this.el){
\r
166 this.el.un("keydown", this.checkTab, this);
\r
170 this.wrap.removeClass('x-trigger-wrap-focus');
\r
172 Ext.form.TriggerField.superclass.onBlur.call(this);
\r
175 beforeBlur : Ext.emptyFn,
\r
178 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
\r
179 validateBlur : function(e){
\r
184 onDisable : function(){
\r
185 Ext.form.TriggerField.superclass.onDisable.call(this);
\r
187 this.wrap.addClass(this.disabledClass);
\r
188 this.el.removeClass(this.disabledClass);
\r
193 onEnable : function(){
\r
194 Ext.form.TriggerField.superclass.onEnable.call(this);
\r
196 this.wrap.removeClass(this.disabledClass);
\r
201 onShow : function(){
\r
203 this.wrap.dom.style.display = '';
\r
204 this.wrap.dom.style.visibility = 'visible';
\r
209 onHide : function(){
\r
210 this.wrap.dom.style.display = 'none';
\r
214 * The function that should handle the trigger's click event. This method does nothing by default until overridden
\r
215 * by an implementing function.
\r
217 * @param {EventObject} e
\r
219 onTriggerClick : Ext.emptyFn
\r
222 * @cfg {Boolean} grow @hide
\r
225 * @cfg {Number} growMin @hide
\r
228 * @cfg {Number} growMax @hide
\r
232 // TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
\r
233 // to be extended by an implementing class. For an example of implementing this class, see the custom
\r
234 // SearchField implementation here: http://extjs.com/deploy/ext/examples/form/custom.html
\r
235 Ext.form.TwinTriggerField = Ext.extend(Ext.form.TriggerField, {
\r
236 initComponent : function(){
\r
237 Ext.form.TwinTriggerField.superclass.initComponent.call(this);
\r
239 this.triggerConfig = {
\r
240 tag:'span', cls:'x-form-twin-triggers', cn:[
\r
241 {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
\r
242 {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
\r
246 getTrigger : function(index){
\r
247 return this.triggers[index];
\r
250 initTrigger : function(){
\r
251 var ts = this.trigger.select('.x-form-trigger', true);
\r
252 this.wrap.setStyle('overflow', 'hidden');
\r
253 var triggerField = this;
\r
254 ts.each(function(t, all, index){
\r
255 t.hide = function(){
\r
256 var w = triggerField.wrap.getWidth();
\r
257 this.dom.style.display = 'none';
\r
258 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
\r
260 t.show = function(){
\r
261 var w = triggerField.wrap.getWidth();
\r
262 this.dom.style.display = '';
\r
263 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
\r
265 var triggerIndex = 'Trigger'+(index+1);
\r
267 if(this['hide'+triggerIndex]){
\r
268 t.dom.style.display = 'none';
\r
270 t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
\r
271 t.addClassOnOver('x-form-trigger-over');
\r
272 t.addClassOnClick('x-form-trigger-click');
\r
274 this.triggers = ts.elements;
\r
277 onTrigger1Click : Ext.emptyFn,
\r
278 onTrigger2Click : Ext.emptyFn
\r
280 Ext.reg('trigger', Ext.form.TriggerField);