ExtJS vtype作为函数

Ale*_*lex 4 extjs

有没有办法在值上测试vType,而不是在表单中?

例如,我有一个自定义vtype实现了ajax验证,但是我也想对电子邮件vtype运行它,所以我希望在我的自定义vtype中运行一些东西.

validate('abc@de.ce','email');
Run Code Online (Sandbox Code Playgroud)

Ash*_*tch 5

您可以使用函数而不是属性,然后您可以调用'em:

Ext.apply(Ext.form.VTypes, {

    // Validates an ajax thingy
    ajax: function(v) {
        // validate against email VType
        return Ext.form.VTypes.email(v);
    },

    // Override the default Ext function, to allow oddly-placed hyphens
    email: function(v) {
        var regex = /^[-\w][-+\.\w]*@[-\w\.]+\.[A-Za-z]{2,4}$/;
        return regex.test(v);
    }
}

Ext.form.VTypes.ajax('abc@de.ce');
Run Code Online (Sandbox Code Playgroud)