Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / docs / source / Field.html
1 <html>\r
2 <head>\r
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    \r
4   <title>The source code</title>\r
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
7 </head>\r
8 <body  onload="prettyPrint();">\r
9     <pre class="prettyprint lang-js"><div id="cls-Ext.form.Field"></div>/**
10  * @class Ext.form.Field
11  * @extends Ext.BoxComponent
12  * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
13  * @constructor
14  * Creates a new Field
15  * @param {Object} config Configuration options
16  * @xtype field
17  */
18 Ext.form.Field = Ext.extend(Ext.BoxComponent,  {
19     <div id="prop-Ext.form.Field-label"></div>/**
20      * <p>The label Element associated with this Field. <b>Only available after this Field has been rendered by a
21      * {@link form Ext.layout.FormLayout} layout manager.</b></p>
22      * @type Ext.Element
23      * @property label
24      */
25     <div id="cfg-Ext.form.Field-inputType"></div>/**
26      * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password, file (defaults
27      * to 'text'). The types 'file' and 'password' must be used to render those field types currently -- there are
28      * no separate Ext components for those. Note that if you use <tt>inputType:'file'</tt>, {@link #emptyText}
29      * is not supported and should be avoided.
30      */
31     <div id="cfg-Ext.form.Field-tabIndex"></div>/**
32      * @cfg {Number} tabIndex The tabIndex for this field. Note this only applies to fields that are rendered,
33      * not those which are built via applyTo (defaults to undefined).
34      */
35     <div id="cfg-Ext.form.Field-value"></div>/**
36      * @cfg {Mixed} value A value to initialize this field with (defaults to undefined).
37      */
38     <div id="cfg-Ext.form.Field-name"></div>/**
39      * @cfg {String} name The field's HTML name attribute (defaults to '').
40      * <b>Note</b>: this property must be set if this field is to be automatically included with
41      * {@link Ext.form.BasicForm#submit form submit()}.
42      */
43     <div id="cfg-Ext.form.Field-cls"></div>/**
44      * @cfg {String} cls A custom CSS class to apply to the field's underlying element (defaults to '').
45      */
46
47     <div id="cfg-Ext.form.Field-invalidClass"></div>/**
48      * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to 'x-form-invalid')
49      */
50     invalidClass : 'x-form-invalid',
51     <div id="cfg-Ext.form.Field-invalidText"></div>/**
52      * @cfg {String} invalidText The error text to use when marking a field invalid and no message is provided
53      * (defaults to 'The value in this field is invalid')
54      */
55     invalidText : 'The value in this field is invalid',
56     <div id="cfg-Ext.form.Field-focusClass"></div>/**
57      * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to 'x-form-focus')
58      */
59     focusClass : 'x-form-focus',
60     <div id="cfg-Ext.form.Field-preventMark"></div>/**
61      * @cfg {Boolean} preventMark
62      * <tt>true</tt> to disable {@link #markInvalid marking the field invalid}.
63      * Defaults to <tt>false</tt>.
64      */
65     <div id="cfg-Ext.form.Field-validationEvent"></div>/**
66      * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
67       automatic validation (defaults to 'keyup').
68      */
69     validationEvent : 'keyup',
70     <div id="cfg-Ext.form.Field-validateOnBlur"></div>/**
71      * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
72      */
73     validateOnBlur : true,
74     <div id="cfg-Ext.form.Field-validationDelay"></div>/**
75      * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation
76      * is initiated (defaults to 250)
77      */
78     validationDelay : 250,
79     <div id="cfg-Ext.form.Field-autoCreate"></div>/**
80      * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
81      * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
82      * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details.  Defaults to:</p>
83      * <pre><code>{tag: 'input', type: 'text', size: '20', autocomplete: 'off'}</code></pre>
84      */
85     defaultAutoCreate : {tag: 'input', type: 'text', size: '20', autocomplete: 'off'},
86     <div id="cfg-Ext.form.Field-fieldClass"></div>/**
87      * @cfg {String} fieldClass The default CSS class for the field (defaults to 'x-form-field')
88      */
89     fieldClass : 'x-form-field',
90     <div id="cfg-Ext.form.Field-msgTarget<p>The"></div>/**
91      * @cfg {String} msgTarget<p>The location where the message text set through {@link #markInvalid} should display.
92      * Must be one of the following values:</p>
93      * <div class="mdetail-params"><ul>
94      * <li><code>qtip</code> Display a quick tip containing the message when the user hovers over the field. This is the default.
95      * <div class="subdesc"><b>{@link Ext.QuickTips#init Ext.QuickTips.init} must have been called for this setting to work.</b></div</li>
96      * <li><code>title</code> Display the message in a default browser title attribute popup.</li>
97      * <li><code>under</code> Add a block div beneath the field containing the error message.</li>
98      * <li><code>side</code> Add an error icon to the right of the field, displaying the message in a popup on hover.</li>
99      * <li><code>[element id]</code> Add the error message directly to the innerHTML of the specified element.</li>
100      * </ul></div>
101      */
102     msgTarget : 'qtip',
103     <div id="cfg-Ext.form.Field-msgFx"></div>/**
104      * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field
105      * (defaults to 'normal').
106      */
107     msgFx : 'normal',
108     <div id="cfg-Ext.form.Field-readOnly"></div>/**
109      * @cfg {Boolean} readOnly <tt>true</tt> to mark the field as readOnly in HTML
110      * (defaults to <tt>false</tt>).
111      * <br><p><b>Note</b>: this only sets the element's readOnly DOM attribute.
112      * Setting <code>readOnly=true</code>, for example, will not disable triggering a
113      * ComboBox or DateField; it gives you the option of forcing the user to choose
114      * via the trigger without typing in the text box. To hide the trigger use
115      * <code>{@link Ext.form.TriggerField#hideTrigger hideTrigger}</code>.</p>
116      */
117     readOnly : false,
118     <div id="cfg-Ext.form.Field-disabled"></div>/**
119      * @cfg {Boolean} disabled True to disable the field (defaults to false).
120      * <p>Be aware that conformant with the <a href="http://www.w3.org/TR/html401/interact/forms.html#h-17.12.1">HTML specification</a>,
121      * disabled Fields will not be {@link Ext.form.BasicForm#submit submitted}.</p>
122      */
123     disabled : false,
124     <div id="cfg-Ext.form.Field-submitValue"></div>/**
125      * @cfg {Boolean} submitValue False to clear the name attribute on the field so that it is not submitted during a form post.
126      * Defaults to <tt>true</tt>.
127      */
128     submitValue: true,
129
130     // private
131     isFormField : true,
132
133     // private
134     msgDisplay: '',
135
136     // private
137     hasFocus : false,
138
139     // private
140     initComponent : function(){
141         Ext.form.Field.superclass.initComponent.call(this);
142         this.addEvents(
143             <div id="event-Ext.form.Field-focus"></div>/**
144              * @event focus
145              * Fires when this field receives input focus.
146              * @param {Ext.form.Field} this
147              */
148             'focus',
149             <div id="event-Ext.form.Field-blur"></div>/**
150              * @event blur
151              * Fires when this field loses input focus.
152              * @param {Ext.form.Field} this
153              */
154             'blur',
155             <div id="event-Ext.form.Field-specialkey"></div>/**
156              * @event specialkey
157              * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed.
158              * To handle other keys see {@link Ext.Panel#keys} or {@link Ext.KeyMap}.
159              * You can check {@link Ext.EventObject#getKey} to determine which key was pressed.
160              * For example: <pre><code>
161 var form = new Ext.form.FormPanel({
162     ...
163     items: [{
164             fieldLabel: 'Field 1',
165             name: 'field1',
166             allowBlank: false
167         },{
168             fieldLabel: 'Field 2',
169             name: 'field2',
170             listeners: {
171                 specialkey: function(field, e){
172                     // e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN,
173                     // e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
174                     if (e.{@link Ext.EventObject#getKey getKey()} == e.ENTER) {
175                         var form = field.ownerCt.getForm();
176                         form.submit();
177                     }
178                 }
179             }
180         }
181     ],
182     ...
183 });
184              * </code></pre>
185              * @param {Ext.form.Field} this
186              * @param {Ext.EventObject} e The event object
187              */
188             'specialkey',
189             <div id="event-Ext.form.Field-change"></div>/**
190              * @event change
191              * Fires just before the field blurs if the field value has changed.
192              * @param {Ext.form.Field} this
193              * @param {Mixed} newValue The new value
194              * @param {Mixed} oldValue The original value
195              */
196             'change',
197             <div id="event-Ext.form.Field-invalid"></div>/**
198              * @event invalid
199              * Fires after the field has been marked as invalid.
200              * @param {Ext.form.Field} this
201              * @param {String} msg The validation message
202              */
203             'invalid',
204             <div id="event-Ext.form.Field-valid"></div>/**
205              * @event valid
206              * Fires after the field has been validated with no errors.
207              * @param {Ext.form.Field} this
208              */
209             'valid'
210         );
211     },
212
213     <div id="method-Ext.form.Field-getName"></div>/**
214      * Returns the {@link Ext.form.Field#name name} or {@link Ext.form.ComboBox#hiddenName hiddenName}
215      * attribute of the field if available.
216      * @return {String} name The field {@link Ext.form.Field#name name} or {@link Ext.form.ComboBox#hiddenName hiddenName}
217      */
218     getName : function(){
219         return this.rendered && this.el.dom.name ? this.el.dom.name : this.name || this.id || '';
220     },
221
222     // private
223     onRender : function(ct, position){
224         if(!this.el){
225             var cfg = this.getAutoCreate();
226
227             if(!cfg.name){
228                 cfg.name = this.name || this.id;
229             }
230             if(this.inputType){
231                 cfg.type = this.inputType;
232             }
233             this.autoEl = cfg;
234         }
235         Ext.form.Field.superclass.onRender.call(this, ct, position);
236         if(this.submitValue === false){
237             this.el.dom.removeAttribute('name');
238         }
239         var type = this.el.dom.type;
240         if(type){
241             if(type == 'password'){
242                 type = 'text';
243             }
244             this.el.addClass('x-form-'+type);
245         }
246         if(this.readOnly){
247             this.setReadOnly(true);
248         }
249         if(this.tabIndex !== undefined){
250             this.el.dom.setAttribute('tabIndex', this.tabIndex);
251         }
252
253         this.el.addClass([this.fieldClass, this.cls]);
254     },
255
256     // private
257     getItemCt : function(){
258         return this.itemCt;
259     },
260
261     // private
262     initValue : function(){
263         if(this.value !== undefined){
264             this.setValue(this.value);
265         }else if(!Ext.isEmpty(this.el.dom.value) && this.el.dom.value != this.emptyText){
266             this.setValue(this.el.dom.value);
267         }
268         <div id="prop-Ext.form.Field-originalValue"></div>/**
269          * The original value of the field as configured in the {@link #value} configuration, or
270          * as loaded by the last form load operation if the form's {@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
271          * setting is <code>true</code>.
272          * @type mixed
273          * @property originalValue
274          */
275         this.originalValue = this.getValue();
276     },
277
278     <div id="method-Ext.form.Field-isDirty"></div>/**
279      * <p>Returns true if the value of this Field has been changed from its original value.
280      * Will return false if the field is disabled or has not been rendered yet.</p>
281      * <p>Note that if the owning {@link Ext.form.BasicForm form} was configured with
282      * {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
283      * then the <i>original value</i> is updated when the values are loaded by
284      * {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#setValues setValues}.</p>
285      * @return {Boolean} True if this field has been changed from its original value (and
286      * is not disabled), false otherwise.
287      */
288     isDirty : function() {
289         if(this.disabled || !this.rendered) {
290             return false;
291         }
292         return String(this.getValue()) !== String(this.originalValue);
293     },
294
295     <div id="method-Ext.form.Field-setReadOnly"></div>/**
296      * Sets the read only state of this field.
297      * @param {Boolean} readOnly Whether the field should be read only.
298      */
299     setReadOnly : function(readOnly){
300         if(this.rendered){
301             this.el.dom.readOnly = readOnly;
302         }
303         this.readOnly = readOnly;
304     },
305
306     // private
307     afterRender : function(){
308         Ext.form.Field.superclass.afterRender.call(this);
309         this.initEvents();
310         this.initValue();
311     },
312
313     // private
314     fireKey : function(e){
315         if(e.isSpecialKey()){
316             this.fireEvent('specialkey', this, e);
317         }
318     },
319
320     <div id="method-Ext.form.Field-reset"></div>/**
321      * Resets the current field value to the originally loaded value and clears any validation messages.
322      * See {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
323      */
324     reset : function(){
325         this.setValue(this.originalValue);
326         this.clearInvalid();
327     },
328
329     // private
330     initEvents : function(){
331         this.mon(this.el, Ext.EventManager.useKeydown ? 'keydown' : 'keypress', this.fireKey,  this);
332         this.mon(this.el, 'focus', this.onFocus, this);
333
334         // standardise buffer across all browsers + OS-es for consistent event order.
335         // (the 10ms buffer for Editors fixes a weird FF/Win editor issue when changing OS window focus)
336         this.mon(this.el, 'blur', this.onBlur, this, this.inEditor ? {buffer:10} : null);
337     },
338
339     // private
340     preFocus: Ext.emptyFn,
341
342     // private
343     onFocus : function(){
344         this.preFocus();
345         if(this.focusClass){
346             this.el.addClass(this.focusClass);
347         }
348         if(!this.hasFocus){
349             this.hasFocus = true;
350             <div id="prop-Ext.form.Field-startValue"></div>/**
351              * <p>The value that the Field had at the time it was last focused. This is the value that is passed
352              * to the {@link #change} event which is fired if the value has been changed when the Field is blurred.</p>
353              * <p><b>This will be undefined until the Field has been visited.</b> Compare {@link #originalValue}.</p>
354              * @type mixed
355              * @property startValue
356              */
357             this.startValue = this.getValue();
358             this.fireEvent('focus', this);
359         }
360     },
361
362     // private
363     beforeBlur : Ext.emptyFn,
364
365     // private
366     onBlur : function(){
367         this.beforeBlur();
368         if(this.focusClass){
369             this.el.removeClass(this.focusClass);
370         }
371         this.hasFocus = false;
372         if(this.validationEvent !== false && (this.validateOnBlur || this.validationEvent == 'blur')){
373             this.validate();
374         }
375         var v = this.getValue();
376         if(String(v) !== String(this.startValue)){
377             this.fireEvent('change', this, v, this.startValue);
378         }
379         this.fireEvent('blur', this);
380         this.postBlur();
381     },
382
383     // private
384     postBlur : Ext.emptyFn,
385
386     <div id="method-Ext.form.Field-isValid"></div>/**
387      * Returns whether or not the field value is currently valid by
388      * {@link #validateValue validating} the {@link #processValue processed value}
389      * of the field. <b>Note</b>: {@link #disabled} fields are ignored.
390      * @param {Boolean} preventMark True to disable marking the field invalid
391      * @return {Boolean} True if the value is valid, else false
392      */
393     isValid : function(preventMark){
394         if(this.disabled){
395             return true;
396         }
397         var restore = this.preventMark;
398         this.preventMark = preventMark === true;
399         var v = this.validateValue(this.processValue(this.getRawValue()));
400         this.preventMark = restore;
401         return v;
402     },
403
404     <div id="method-Ext.form.Field-validate"></div>/**
405      * Validates the field value
406      * @return {Boolean} True if the value is valid, else false
407      */
408     validate : function(){
409         if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
410             this.clearInvalid();
411             return true;
412         }
413         return false;
414     },
415
416     <div id="method-Ext.form.Field-processValue"></div>/**
417      * This method should only be overridden if necessary to prepare raw values
418      * for validation (see {@link #validate} and {@link #isValid}).  This method
419      * is expected to return the processed value for the field which will
420      * be used for validation (see validateValue method).
421      * @param {Mixed} value
422      */
423     processValue : function(value){
424         return value;
425     },
426
427     /**
428      * @private
429      * Subclasses should provide the validation implementation by overriding this
430      * @param {Mixed} value
431      */
432     validateValue : function(value){
433         return true;
434     },
435
436     <div id="method-Ext.form.Field-getActiveError"></div>/**
437      * Gets the active error message for this field.
438      * @return {String} Returns the active error message on the field, if there is no error, an empty string is returned.
439      */
440     getActiveError : function(){
441         return this.activeError || '';
442     },
443
444     <div id="method-Ext.form.Field-markInvalid"></div>/**
445      * <p>Display an error message associated with this field, using {@link #msgTarget} to determine how to
446      * display the message and applying {@link #invalidClass} to the field's UI element.</p>
447      * <p><b>Note</b>: this method does not cause the Field's {@link #validate} method to return <code>false</code>
448      * if the value does <i>pass</i> validation. So simply marking a Field as invalid will not prevent
449      * submission of forms submitted with the {@link Ext.form.Action.Submit#clientValidation} option set.</p>
450      * {@link #isValid invalid}.
451      * @param {String} msg (optional) The validation message (defaults to {@link #invalidText})
452      */
453     markInvalid : function(msg){
454         if(!this.rendered || this.preventMark){ // not rendered
455             return;
456         }
457         msg = msg || this.invalidText;
458
459         var mt = this.getMessageHandler();
460         if(mt){
461             mt.mark(this, msg);
462         }else if(this.msgTarget){
463             this.el.addClass(this.invalidClass);
464             var t = Ext.getDom(this.msgTarget);
465             if(t){
466                 t.innerHTML = msg;
467                 t.style.display = this.msgDisplay;
468             }
469         }
470         this.activeError = msg;
471         this.fireEvent('invalid', this, msg);
472     },
473
474     <div id="method-Ext.form.Field-clearInvalid"></div>/**
475      * Clear any invalid styles/messages for this field
476      */
477     clearInvalid : function(){
478         if(!this.rendered || this.preventMark){ // not rendered
479             return;
480         }
481         this.el.removeClass(this.invalidClass);
482         var mt = this.getMessageHandler();
483         if(mt){
484             mt.clear(this);
485         }else if(this.msgTarget){
486             this.el.removeClass(this.invalidClass);
487             var t = Ext.getDom(this.msgTarget);
488             if(t){
489                 t.innerHTML = '';
490                 t.style.display = 'none';
491             }
492         }
493         delete this.activeError;
494         this.fireEvent('valid', this);
495     },
496
497     // private
498     getMessageHandler : function(){
499         return Ext.form.MessageTargets[this.msgTarget];
500     },
501
502     // private
503     getErrorCt : function(){
504         return this.el.findParent('.x-form-element', 5, true) || // use form element wrap if available
505             this.el.findParent('.x-form-field-wrap', 5, true);   // else direct field wrap
506     },
507
508     // Alignment for 'under' target
509     alignErrorEl : function(){
510         this.errorEl.setWidth(this.getErrorCt().getWidth(true) - 20);
511     },
512
513     // Alignment for 'side' target
514     alignErrorIcon : function(){
515         this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
516     },
517
518     <div id="method-Ext.form.Field-getRawValue"></div>/**
519      * Returns the raw data value which may or may not be a valid, defined value.  To return a normalized value see {@link #getValue}.
520      * @return {Mixed} value The field value
521      */
522     getRawValue : function(){
523         var v = this.rendered ? this.el.getValue() : Ext.value(this.value, '');
524         if(v === this.emptyText){
525             v = '';
526         }
527         return v;
528     },
529
530     <div id="method-Ext.form.Field-getValue"></div>/**
531      * Returns the normalized data value (undefined or emptyText will be returned as '').  To return the raw value see {@link #getRawValue}.
532      * @return {Mixed} value The field value
533      */
534     getValue : function(){
535         if(!this.rendered) {
536             return this.value;
537         }
538         var v = this.el.getValue();
539         if(v === this.emptyText || v === undefined){
540             v = '';
541         }
542         return v;
543     },
544
545     <div id="method-Ext.form.Field-setRawValue"></div>/**
546      * Sets the underlying DOM field's value directly, bypassing validation.  To set the value with validation see {@link #setValue}.
547      * @param {Mixed} value The value to set
548      * @return {Mixed} value The field value that is set
549      */
550     setRawValue : function(v){
551         return this.rendered ? (this.el.dom.value = (Ext.isEmpty(v) ? '' : v)) : '';
552     },
553
554     <div id="method-Ext.form.Field-setValue"></div>/**
555      * Sets a data value into the field and validates it.  To set the value directly without validation see {@link #setRawValue}.
556      * @param {Mixed} value The value to set
557      * @return {Ext.form.Field} this
558      */
559     setValue : function(v){
560         this.value = v;
561         if(this.rendered){
562             this.el.dom.value = (Ext.isEmpty(v) ? '' : v);
563             this.validate();
564         }
565         return this;
566     },
567
568     // private, does not work for all fields
569     append : function(v){
570          this.setValue([this.getValue(), v].join(''));
571     }
572
573     <div id="cfg-Ext.form.Field-autoWidth"></div>/**
574      * @cfg {Boolean} autoWidth @hide
575      */
576     <div id="cfg-Ext.form.Field-autoHeight"></div>/**
577      * @cfg {Boolean} autoHeight @hide
578      */
579
580     <div id="cfg-Ext.form.Field-autoEl"></div>/**
581      * @cfg {String} autoEl @hide
582      */
583 });
584
585
586 Ext.form.MessageTargets = {
587     'qtip' : {
588         mark: function(field, msg){
589             field.el.addClass(field.invalidClass);
590             field.el.dom.qtip = msg;
591             field.el.dom.qclass = 'x-form-invalid-tip';
592             if(Ext.QuickTips){ // fix for floating editors interacting with DND
593                 Ext.QuickTips.enable();
594             }
595         },
596         clear: function(field){
597             field.el.removeClass(field.invalidClass);
598             field.el.dom.qtip = '';
599         }
600     },
601     'title' : {
602         mark: function(field, msg){
603             field.el.addClass(field.invalidClass);
604             field.el.dom.title = msg;
605         },
606         clear: function(field){
607             field.el.dom.title = '';
608         }
609     },
610     'under' : {
611         mark: function(field, msg){
612             field.el.addClass(field.invalidClass);
613             if(!field.errorEl){
614                 var elp = field.getErrorCt();
615                 if(!elp){ // field has no container el
616                     field.el.dom.title = msg;
617                     return;
618                 }
619                 field.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
620                 field.on('resize', field.alignErrorEl, field);
621                 field.on('destroy', function(){
622                     Ext.destroy(this.errorEl);
623                 }, field);
624             }
625             field.alignErrorEl();
626             field.errorEl.update(msg);
627             Ext.form.Field.msgFx[field.msgFx].show(field.errorEl, field);
628         },
629         clear: function(field){
630             field.el.removeClass(field.invalidClass);
631             if(field.errorEl){
632                 Ext.form.Field.msgFx[field.msgFx].hide(field.errorEl, field);
633             }else{
634                 field.el.dom.title = '';
635             }
636         }
637     },
638     'side' : {
639         mark: function(field, msg){
640             field.el.addClass(field.invalidClass);
641             if(!field.errorIcon){
642                 var elp = field.getErrorCt();
643                 if(!elp){ // field has no container el
644                     field.el.dom.title = msg;
645                     return;
646                 }
647                 field.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
648                 field.on('resize', field.alignErrorIcon, field);
649                 field.on('destroy', function(){
650                     Ext.destroy(this.errorIcon);
651                 }, field);
652             }
653             field.alignErrorIcon();
654             field.errorIcon.dom.qtip = msg;
655             field.errorIcon.dom.qclass = 'x-form-invalid-tip';
656             field.errorIcon.show();
657         },
658         clear: function(field){
659             field.el.removeClass(field.invalidClass);
660             if(field.errorIcon){
661                 field.errorIcon.dom.qtip = '';
662                 field.errorIcon.hide();
663             }else{
664                 field.el.dom.title = '';
665             }
666         }
667     }
668 };
669
670 // anything other than normal should be considered experimental
671 Ext.form.Field.msgFx = {
672     normal : {
673         show: function(msgEl, f){
674             msgEl.setDisplayed('block');
675         },
676
677         hide : function(msgEl, f){
678             msgEl.setDisplayed(false).update('');
679         }
680     },
681
682     slide : {
683         show: function(msgEl, f){
684             msgEl.slideIn('t', {stopFx:true});
685         },
686
687         hide : function(msgEl, f){
688             msgEl.slideOut('t', {stopFx:true,useDisplay:true});
689         }
690     },
691
692     slideRight : {
693         show: function(msgEl, f){
694             msgEl.fixDisplay();
695             msgEl.alignTo(f.el, 'tl-tr');
696             msgEl.slideIn('l', {stopFx:true});
697         },
698
699         hide : function(msgEl, f){
700             msgEl.slideOut('l', {stopFx:true,useDisplay:true});
701         }
702     }
703 };
704 Ext.reg('field', Ext.form.Field);
705 </pre>    \r
706 </body>\r
707 </html>