⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 field.js

📁 ext js demo ext学习资料
💻 JS
📖 第 1 页 / 共 2 页
字号:
        }        this.hasFocus = true;        this.startValue = this.getValue();        this.fireEvent("focus", this);    },    beforeBlur : Ext.emptyFn,    // private    onBlur : function(){        this.beforeBlur();    this.el.removeClass(this.focusClass);        this.hasFocus = false;        if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){            this.validate();        }        var v = this.getValue();        if(v != this.startValue){            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;    },    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     * @param {String} msg The validation message     */    markInvalid : function(msg){        if(!this.rendered || this.preventMark){ // not rendered            return;        }        this.el.addClass(this.invalidClass);        msg = msg || this.invalidText;        switch(this.msgTarget){            case 'qtip':                this.el.dom.qtip = msg;                this.el.dom.qclass = 'x-form-invalid-tip';                if(Ext.QuickTips){ // fix for floating editors interacting with DND                    Ext.QuickTips.enable();                }                break;            case 'title':                this.el.dom.title = msg;                break;            case 'under':                if(!this.errorEl){                    var elp = this.el.findParent('.x-form-element', 5, true);                    this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});                    this.errorEl.setWidth(elp.getWidth(true)-20);                }                this.errorEl.update(msg);                Ext.form.Field.msgFx[this.msgFx].show(this.errorEl, this);                break;            case 'side':                if(!this.errorIcon){                    var elp = this.el.findParent('.x-form-element', 5, true);                    this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});                }                this.alignErrorIcon();                this.errorIcon.dom.qtip = msg;                this.errorIcon.dom.qclass = 'x-form-invalid-tip';                this.errorIcon.show();                this.on('resize', this.alignErrorIcon, this);                break;            default:                var t = Ext.getDom(this.msgTarget);                t.innerHTML = msg;                t.style.display = this.msgDisplay;                break;        }        this.fireEvent('invalid', this, msg);    },    // private    alignErrorIcon : function(){        this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);    },    /**     * Clear any invalid styles/messages for this field     */    clearInvalid : function(){        if(!this.rendered || this.preventMark){ // not rendered            return;        }        this.el.removeClass(this.invalidClass);        switch(this.msgTarget){            case 'qtip':                this.el.dom.qtip = '';                break;            case 'title':                this.el.dom.title = '';                break;            case 'under':                if(this.errorEl){                    Ext.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);                }                break;            case 'side':                if(this.errorIcon){                    this.errorIcon.dom.qtip = '';                    this.errorIcon.hide();                    this.un('resize', this.alignErrorIcon, this);                }                break;            default:                var t = Ext.getDom(this.msgTarget);                t.innerHTML = '';                t.style.display = 'none';                break;        }        this.fireEvent('valid', this);    },    /**     * 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.el.getValue();        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(){        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     */    setRawValue : function(v){        return this.el.dom.value = (v === null || v === undefined ? '' : 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     */    setValue : function(v){        this.value = v;        if(this.rendered){            this.el.dom.value = (v === null || v === undefined ? '' : v);            this.validate();        }    },    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);        return s;    },    adjustWidth : function(tag, w){        tag = tag.toLowerCase();        if(typeof w == 'number' && Ext.isStrict && !Ext.isSafari){            if(Ext.isIE && (tag == 'input' || tag == 'textarea')){                if(tag == 'input'){                    return w + 2;                }                if(tag = 'textarea'){                    return w-2;                }            }else if(Ext.isOpera){                if(tag == 'input'){                    return w + 2;                }                if(tag = 'textarea'){                    return w-2;                }            }        }        return w;    }});// 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});        }    }};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -