ITeye博客

最小长度与最大长度验证

20444465 · 2011-07-21 12:25 · ExtJs · Web前端 · Markdown

        //取值范围(选择数字时显示)
        layout : 'tableform',
        border : false,
        id : 'customfields_min_max_length_id',
        hidden : true,
        items : [{//最小长度(MIN_LENGTH)
            xtype : 'numberfield',
            fieldLabel : '取值范围',
            // name : 'customfields_min_length',
            name : 'MIN_LENGTH',
            id : 'customfields_min_length_id',
            //readOnly : (customFields_id != null && customFields_id != "") ? true : false,
            style : 'background: url(Resources/images/pen.gif) no-repeat 3px center;padding-left:15px;',
            maxLength : 5,
            maxLengthText : '最小长度不能超过5位',
            width : 200
        }, {
            xtype : 'label',
            text : '~',
            style : 'margin-left:30px;'
        }, {
            //最大长度(MAX_LENGTH)
            xtype : 'numberfield',
            labelSeparator : "",
            name : 'MAX_LENGTH',
            id : 'customfields_max_length_id',
            style : 'background: url(Resources/images/pen.gif) no-repeat 3px center;padding-left:15px;margin-left:-30px',
            validator : function() {
                if (Ext.getCmp('customfields_min_length_id').getValue() && Ext.getCmp('customfields_max_length_id').getValue()) {
                    var max = Ext.getCmp('customfields_max_length_id').getValue();
                    var min = Ext.getCmp('customfields_min_length_id').getValue();
                    if (min > max) {
                        Ext.getCmp('customfields_max_length_id').invalidText = "最大长度不能小于最小长度";
                        return false;
                    } else {
                        Ext.getCmp('customfields_max_length_id').clearInvalid();
                        return true;
                    }
                }
                return true;
            },
            maxLength : 5,
            maxLengthText : '最大长度不能超过5位',
            width : 200
        }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。