微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript-需要用于extjs4增强功能的密码验证的高级VType

我想在从http://dev.sencha.com/deploy/ext-4.0.2a/examples/form/adv-vtypes.html取得的extjs上使用高级VType实施密码验证,但是如果密码确认没有值(如果密码值为’test,则确认密码文本字段似乎无法验证密码文本字段的更改) ‘并确认密码值为空白,则该表格有效).我确定这是不对的.
如何通过以下条件使/确认密码文本字段有效/无效:

>如果密码值不等于确认密码值,请确认
密码无效(即使确认密码值为空)
>如果密码值为空白并确认密码值为空白,则
然后确认密码有效
>如果密码值等于确认密码值,则确认
密码有效

谢谢

解决方法:

好的,看来我已经解决了自己的问题.
正如分子人所说,这是(轻松)实现的.

我需要重写Ext.form.field.Text.getErrors来解决这个问题

Ext.form.field.Text.override({
    getErrors: function(value) {
        var me = this,
            errors = me.callParent(arguments),
            validator = me.validator,
            emptyText = me.emptyText,
            allowBlank = me.allowBlank,
            vtype = me.vtype,
            vtypes = Ext.form.field.VTypes,
            regex = me.regex,
            format = Ext.String.format,
            msg;

        value = value || me.processRawValue(me.getRawValue());

        if (Ext.isFunction(validator)) {
            msg = validator.call(me, value);
            if (msg !== true) {
                errors.push(msg);
            }
        }

        if (value.length < 1 || value === emptyText) {
            if (!allowBlank) {
                errors.push(me.blankText);
            }
            //FIX BY ME : NEED TO COMMENT THIS BECAUSE ITS CAN IGnorING VTYPE AS ITS IMMEDIATELY RETURN ERRORS
            //return errors;
        }

        if (value.length < me.minLength) {
            errors.push(format(me.minLengthText, me.minLength));
        }

        if (value.length > me.maxLength) {
            errors.push(format(me.maxLengthText, me.maxLength));
        }

        if (vtype) {
            if(!vtypes[vtype](value, me)){
                errors.push(me.vtypeText || vtypes[vtype +'Text']);
            }
        }

        if (regex && !regex.test(value)) {
            errors.push(me.regexText || me.invalidText);
        }

        return errors;
    }
});

这是完整的代码http://jsfiddle.net/gajahlemu/SY6WC/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐