📄 field.js
字号:
/*
* Ext JS Library 1.0.1
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://www.extjs.com/license
*/
/** * @class Ext.form.Field * @extends Ext.Component * Base class for form fields that provides default event handling, sizing, value handling and other functionality. * @constructor * Creates a new Field * @param {Object} config Configuration options */Ext.form.Field = function(config){ Ext.form.Field.superclass.constructor.call(this, config); this.addEvents({ /** * @event focus * Fires when this field receives input focus * @param {Ext.form.Field} this */ focus : true, /** * @event blur * Fires when * @param {Ext.form.Field} this */ blur : true, /** * @event specialkey * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check * {@link Ext.EventObject#getKey} to determine which key was pressed. * @param {Ext.form.Field} this * @param {Ext.EventObject} e The event object */ specialkey : true, /** * @event change * Fires just before the field blurs if the field value has changed * @param {Ext.form.Field} this * @param {Mixed} value The changed value * @param {Mixed} value The original value */ change : true, /** * @event invalid * Fires after the field has been marked as invalid * @param {Ext.form.Field} this * @param {String} msg The validation message */ invalid : true, /** * @event valid * Fires after the field has been validated with no errors * @param {Ext.form.Field} this */ valid : true });};Ext.extend(Ext.form.Field, Ext.Component, { /** * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid") */ invalidClass : "x-form-invalid", /** * @cfg {String} invalidText The error text to use when marking a field invalid and no message is provided (defaults to "The value in this field is invalid") */ invalidText : "The value in this field is invalid", /** * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus") */ focusClass : "x-form-focus", /** * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable automatic validation. (defaults to "keyup") */ validationEvent : "keyup", /** * @cfg {String/Boolean} validateOnBlur Defaults to true. */ validateOnBlur : true, /** * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250) */ validationDelay : 250, /** * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to * {tag: "input", type: "text", size: "20", autocomplete: "off"}) */ defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "off"}, /** * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field") */ fieldClass: "x-form-field", /** * @cfg {String} msgTarget The location where error text should display. Should be one of the following values (defaults to 'qtip'): *<pre>Value Description----------- ----------------------------------------------------------------------qtip Display a quick tip when the user hovers over the fieldtitle Display a default browser title attribute popupunder Add a block div beneath the field containing the error textside Add an error icon to the right of the field with a popup on hover[element id] Add the error text directly to the innerHTML of the specified element</pre> */ msgTarget: 'qtip', /** * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field (defaults to 'normal'). */ msgFx : 'normal', /** * @cfg {String} inputType The type attribute for input fields - e.g. radio, text, password. (defaults to "text") */ inputType : undefined, // private isFormField : true, // private hasFocus : false, /** * @cfg {Mixed} value A value to initialize this field with */ value : undefined, /** * Returns the name attribute of the field if available * @return {String} name The field name */ getName: function(){ return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || ''); }, /** * Apply the behaviors of this component to an existing element. <b>This is used instead of render().</b> * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element * @return {Ext.form.Field} this */ applyTo : function(target){ this.target = target; this.el = Ext.get(target); this.render(this.el.dom.parentNode); return this; }, // private onRender : function(ct, position){ if(this.el){ this.el = Ext.get(this.el); if(!this.target){ ct.dom.appendChild(this.el.dom); } }else { var cfg = this.getAutoCreate(); if(!cfg.name){ cfg.name = this.name || this.id; } if(this.inputType){ cfg.type = this.inputType; } if(this.tabIndex !== undefined){ cfg.tabIndex = this.tabIndex; } this.el = ct.createChild(cfg, position); } var type = this.el.dom.type; if(type){ if(type == 'password'){ type = 'text'; } this.el.addClass('x-form-'+type); } if(!this.customSize && (this.width || this.height)){ this.setSize(this.width || "", this.height || ""); } if(this.readOnly){ this.el.dom.readOnly = true; } this.el.addClass([this.fieldClass, this.cls]); this.initValue(); }, // private initValue : function(){ if(this.value !== undefined){ this.setValue(this.value); }else if(this.el.dom.value.length > 0){ this.setValue(this.el.dom.value); } }, // private afterRender : function(){ Ext.form.Field.superclass.afterRender.call(this); this.initEvents(); }, // private fireKey : function(e){ if(e.isNavKeyPress()){ this.fireEvent("specialkey", this, e); } }, /** * Resets the current field value to the originally-loaded value and clears any validation messages */ reset : function(){ this.setValue(this.originalValue); this.clearInvalid(); }, // private initEvents : function(){ this.el.on(Ext.isIE ? "keydown" : "keypress", this.fireKey, this); this.el.on("focus", this.onFocus, this); this.el.on("blur", this.onBlur, this); // reference to original value for reset this.originalValue = this.getValue(); }, // private onFocus : function(){ if(!Ext.isOpera){ // don't touch in Opera this.el.addClass(this.focusClass); } this.hasFocus = true; this.startValue = this.getValue(); this.fireEvent("focus", this); }, // private onBlur : function(){ this.el.removeClass(this.focusClass); this.hasFocus = false; if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){ this.validate(); } var v = this.getValue();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -