Extjs项目中uxForm.js

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:34   1938   0
Ext.namespace("Ext.ux");

Ext.override(Ext.form.TextField, {      //区别汉字和英文的长度
    validateValue : function(value){
     
     var strLen = this.countStrLen(value);
     
        if(value.length < 1 || value === this.emptyText){ // if it's blank
             if(this.allowBlank){
                 this.clearInvalid();
                 return true;
             }else{
                 this.markInvalid(this.blankText);
                 return false;
             }
        }
        if(value.length < this.minLength){
            this.markInvalid(String.format(this.minLengthText, this.minLength));
            return false;
        }
        if(strLen > this.maxLength){
            this.markInvalid(String.format(this.maxLengthText, this.maxLength));
            return false;
        }
        if(this.vtype){
            var vt = Ext.form.VTypes;
            if(!vt[this.vtype](value, this)){
                this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
                return false;
            }
        }
        if(typeof this.validator == "function"){
            var msg = this.validator(value);
            if(msg !== true){
                this.markInvalid(msg);
                return false;
            }
        }
        if(this.regex && !this.regex.test(value)){
            this.markInvalid(this.regexText);
            return false;
        }
        return true;
    },
    countStrLen: function(strTemp) {  //计算字符串的长度,区分英文和汉字
        var  i,sum;  
        sum=0;  
        for(i=0;i<strTemp.length;i++) {  
            if  ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))  
                sum=sum+1;  
            else   
                sum=sum+2;  
        }  
        return  sum;  
    }
});

Ext.ux.Form = Ext.extend(Ext.form.FormPanel, {
    frame: true,
    bodyStyle:"padding: 5px 5px 0",
    initComponent: function() {
     Ext.ux.Form.superclass.initComponent.call(this);
    },
    initEvents : function(){
        Ext.ux.Form.superclass.initEvents.call(this);
    },
    createButton: function(text,handler) {
     var btn = new Ext.Button({
         text: text,
         handler: handler
     });
     return btn;
    },
    createTextField: function(fieldLabel, name, anchor, blankText, vtype, maxLength, maxLengthText,inputType, colspan) {    //生成一个通用的TextField
        var tf = new Ext.form.TextField({
            fieldLabel: fieldLabel,
            name: name,
            xtype: 'textfield',
            readOnly: false,
            allowBlank: false,
            anchor: anchor,
            blankText: '该选项为必填项,请输入内容...',
            vtype: vtype,
            maxLength: maxLength,
            maxLengthText: maxLengthText,
            inputType:inputType,
            colspan: colspan
        });
        return tf;
    },
    createNumberField: function(fieldLabel, name, anchor, decimalPrecision, colspan) {    //生成一个通用的TextField
        var nf = new Ext.form.NumberField({
            fieldLabel: fieldLabel,
            name: name,
            readOnly: false,
            allowBlank: false,
            allowNegative :false,//值为false时只允许为正数(默认为 true,即默认允许为负数)
            decimalPrecision :decimalPrecision ,//设置小数点后最大精确位数(默认为 2)。
            anchor: anchor,
            cls:'forbiddenZH',//禁用中文输入法
            blankText: '该选项为必填项,请输入内容...',
            colspan: colspan
        });
        return nf;
    },
    createPassWordField: function(fieldLabel, name, anchor, blankText, vtype, maxLength, maxLengthText) {  //生成一个通用的密码输入框  
        var tf = new Ext.form.TextField({
            fieldLabel: fieldLabel,
            name: name,
            xtype: 'textfield',
            inputType :'password',
            readOnly: false,
            allowBlank: false,
            anchor: anchor,
            blankText: '该选项为必填项,请输入内容...',
            vtype: vtype,
            maxLength: maxLength,
            maxLengthText: maxLengthText
        });
        return tf;
    },
    createRadio: function(boxLabel,name,checked,inputValue) {    //生成一个通用的Radio
        var radio = new Ext.form.Radio({
            boxLabel:boxLabel,
            checked:checked,
            name:name,
            labelSeparator:"",
            inputValue:inputValue,
            anchor:"90%"
        });
        return radio;
    },
    createCombo: function(fieldLabel,id,name,formName,anchor,url,extra1,extra2,colspan) {    //生成一个通用的ComboBox
        var combo = new Ext.form.ComboBox({
         colspan:colspan,
         autoLoad: true,
            fieldLabel: fieldLabel,
            emptyText: '请选择...',
            isFormField: true,
            anchor: anchor,
            mode: 'local',//数据模式,local代表本地数据 
            hiddenName :formName,//提交到后台的input的name,重要
            name:formName,//name只是改下拉的名称,几乎没有作用
            allowBlank: false,
            blankText:'请选择...',
            forceSelection: true,//X\YK[[][PΚ][P[[Θ[[	N[	NJN]\XKX]U^\XN[[Y[X[KZY[[H\H	N]^K^\XJY[X[Y[X[N[YKZYZY[[[[JN]\NKX]RY[[[Y[X[JH\Y[	N]^KY[Y[X[Y[X[N[YBJN]\Y[KX]R[Y][[Y[X[[H$9. 9.*`&[Y]\H	N]^K[Y]Y[X[Y[X[ZY[[[XS[[[XT\Y][[Z[Y\ΖNdNNiNNdNJN]\NKX]P][[^JH\	N]^][Y	NY	N^^[\NBJN]\KX]Q]QY[[[Y[X[KX][H\	N]^K]QY[
Y[X[Y[X[NKX]X][[[[[Y]XN[.#z b[^	N"yNJN]\KX]SX[[[Y[X[^
H\X[	N]^KX[
LZY
Y[X[Y[X[^^JN]\X[KX]Q]S[Y[[[Y[X[KX][H\	N]^K]QY[
Y[X[Y[X[Y	NX\YNNKX]X][[[[[Y]XN[.#z b[^	N"yNJN]\K
9b&"$B
	\[HY[X[9!
	\[H[YH9.z"d#ykd
	\[HY[[YH
	\[H\:+`T
	\[H[
	]\
X]UYPX[[Y[X[[YKY[[YK\[H\	N]^^YPXY[X[Y[X[\N[\\[[[Y[[YNY[[YKNY[[YK[YN[YK[[JN]\BJN^YI^^JNOO
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP