📄 field.js
字号:
this.fireEvent('change', this, v, this.startValue); } this.fireEvent("blur", this); }, /** * Returns whether or not the field value is currently valid * @param {Boolean} preventMark True to disable marking the field invalid * @return {Boolean} True if the value is valid, else false */ isValid : function(preventMark){ if(this.disabled){ return true; } var restore = this.preventMark; this.preventMark = preventMark === true; var v = this.validateValue(this.processValue(this.getRawValue())); this.preventMark = restore; return v; }, /** * Validates the field value * @return {Boolean} True if the value is valid, else false */ validate : function(){ if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){ this.clearInvalid(); return true; } return false; }, // protected - should be overridden by subclasses if necessary to prepare raw values for validation processValue : function(value){ return value; }, // private // Subclasses should provide the validation implementation by overriding this validateValue : function(value){ return true; }, /** * Mark this field as invalid, using {@link #msgTarget} to determine how to display the error and * applying {@link #invalidClass} to the field's element. * @param {String} msg (optional) The validation message (defaults to {@link #invalidText}) */ markInvalid : function(msg){ if(!this.rendered || this.preventMark){ // not rendered return; } msg = msg || this.invalidText; var mt = this.getMessageHandler(); if(mt){ mt.mark(this, msg); }else if(this.msgTarget){ this.el.addClass(this.invalidClass); var t = Ext.getDom(this.msgTarget); if(t){ t.innerHTML = msg; t.style.display = this.msgDisplay; } } this.fireEvent('invalid', this, msg); }, /** * Clear any invalid styles/messages for this field */ clearInvalid : function(){ if(!this.rendered || this.preventMark){ // not rendered return; } this.el.removeClass(this.invalidClass); var mt = this.getMessageHandler(); if(mt){ mt.clear(this); }else if(this.msgTarget){ this.el.removeClass(this.invalidClass); var t = Ext.getDom(this.msgTarget); if(t){ t.innerHTML = ''; t.style.display = 'none'; } } this.fireEvent('valid', this); }, // private getMessageHandler : function(){ return Ext.form.MessageTargets[this.msgTarget]; }, // private getErrorCt : function(){ return this.el.findParent('.x-form-element', 5, true) || // use form element wrap if available this.el.findParent('.x-form-field-wrap', 5, true); // else direct field wrap }, // private alignErrorIcon : function(){ this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]); }, /** * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}. * @return {Mixed} value The field value */ getRawValue : function(){ var v = this.rendered ? this.el.getValue() : Ext.value(this.value, ''); if(v === this.emptyText){ v = ''; } return v; }, /** * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}. * @return {Mixed} value The field value */ getValue : function(){ if(!this.rendered) { return this.value; } var v = this.el.getValue(); if(v === this.emptyText || v === undefined){ v = ''; } return v; }, /** * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}. * @param {Mixed} value The value to set * @return {Mixed} value The field value that is set */ setRawValue : function(v){ return this.el.dom.value = (Ext.isEmpty(v) ? '' : v); }, /** * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}. * @param {Mixed} value The value to set * @return {Ext.form.Field} this */ setValue : function(v){ this.value = v; if(this.rendered){ this.el.dom.value = (Ext.isEmpty(v) ? '' : v); this.validate(); } return this; }, // private, does not work for all fields append :function(v){ this.setValue([this.getValue(), v].join('')); }, // private adjustSize : function(w, h){ var s = Ext.form.Field.superclass.adjustSize.call(this, w, h); s.width = this.adjustWidth(this.el.dom.tagName, s.width); if(this.offsetCt){ var ct = this.getItemCt(); s.width -= ct.getFrameWidth('lr'); s.height -= ct.getFrameWidth('tb'); } return s; }, // private adjustWidth : function(tag, w){ tag = tag.toLowerCase(); if(typeof w == 'number' && !Ext.isWebKit && !this.normalWidth){ if(Ext.isIE && (tag == 'input' || tag == 'textarea')){ if(tag == 'input' && !Ext.isStrict){ return this.inEditor ? w : w - 3; } if(tag == 'input' && Ext.isStrict){ return w - (Ext.isIE6 ? 4 : 1); } if(tag == 'textarea' && Ext.isStrict){ return w-2; } }else if(Ext.isOpera && Ext.isStrict){ if(tag == 'input'){ return w + 2; } if(tag == 'textarea'){ return w-2; } } } return w; } /** * @cfg {Boolean} autoWidth @hide */ /** * @cfg {Boolean} autoHeight @hide */ /** * @cfg {String} autoEl @hide */});Ext.form.MessageTargets = { 'qtip' : { mark: function(field, msg){ field.el.addClass(field.invalidClass); field.el.dom.qtip = msg; field.el.dom.qclass = 'x-form-invalid-tip'; if(Ext.QuickTips){ // fix for floating editors interacting with DND Ext.QuickTips.enable(); } }, clear: function(field){ field.el.removeClass(field.invalidClass); field.el.dom.qtip = ''; } }, 'title' : { mark: function(field, msg){ field.el.addClass(field.invalidClass); field.el.dom.title = msg; }, clear: function(field){ field.el.dom.title = ''; } }, 'under' : { mark: function(field, msg){ field.el.addClass(field.invalidClass); if(!field.errorEl){ var elp = field.getErrorCt(); if(!elp){ // field has no container el field.el.dom.title = msg; return; } field.errorEl = elp.createChild({cls:'x-form-invalid-msg'}); field.errorEl.setWidth(elp.getWidth(true)-20); } field.errorEl.update(msg); Ext.form.Field.msgFx[field.msgFx].show(field.errorEl, field); }, clear: function(field){ field.el.removeClass(field.invalidClass); if(field.errorEl){ Ext.form.Field.msgFx[field.msgFx].hide(field.errorEl, field); }else{ field.el.dom.title = ''; } } }, 'side' : { mark: function(field, msg){ field.el.addClass(field.invalidClass); if(!field.errorIcon){ var elp = field.getErrorCt(); if(!elp){ // field has no container el field.el.dom.title = msg; return; } field.errorIcon = elp.createChild({cls:'x-form-invalid-icon'}); } field.alignErrorIcon(); field.errorIcon.dom.qtip = msg; field.errorIcon.dom.qclass = 'x-form-invalid-tip'; field.errorIcon.show(); field.on('resize', field.alignErrorIcon, field); }, clear: function(field){ field.el.removeClass(field.invalidClass); if(field.errorIcon){ field.errorIcon.dom.qtip = ''; field.errorIcon.hide(); field.un('resize', field.alignErrorIcon, field); }else{ field.el.dom.title = ''; } } }};// anything other than normal should be considered experimentalExt.form.Field.msgFx = { normal : { show: function(msgEl, f){ msgEl.setDisplayed('block'); }, hide : function(msgEl, f){ msgEl.setDisplayed(false).update(''); } }, slide : { show: function(msgEl, f){ msgEl.slideIn('t', {stopFx:true}); }, hide : function(msgEl, f){ msgEl.slideOut('t', {stopFx:true,useDisplay:true}); } }, slideRight : { show: function(msgEl, f){ msgEl.fixDisplay(); msgEl.alignTo(f.el, 'tl-tr'); msgEl.slideIn('l', {stopFx:true}); }, hide : function(msgEl, f){ msgEl.slideOut('l', {stopFx:true,useDisplay:true}); } }};Ext.reg('field', Ext.form.Field);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -