如何让角度$ asyncValidator在模糊时触发但在输入时使用常规验证器 [英] How to let angular $asyncValidator fire on blur but normal validators on input

查看:24
本文介绍了如何让角度$ asyncValidator在模糊时触发但在输入时使用常规验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让有角度的1.3 $ asyncValidators仅在模糊时触发,而不是在用户输入时触发?我希望$ validators表现为默认值.

Is it possible to let angular 1.3 $asyncValidators only fire on blur and not as the user inputs? I want the $validators to behave as per default.

我知道我可以使用 ng-model-options 来更新onBlur模型,但是所有验证都会在模糊时触发.

I know I can use ng-model-options to update the model onBlur but then all validations are fired on blur.

推荐答案

当前(angularjs版本1.3)尚无机制可以做到这一点.

Currently (angularjs version 1.3) there is no mechanism to do this.

最后,我添加了一个模糊事件来触发验证器,然后设置有效性

In the end I added a blur event to fire the validators and then set the validity

element.on('blur', function () {
    if (ngModel.$dirty) {
        doServerSideValidation();
    } else {
        ngModel.$setValidity(key, true);
    }
});

doServerSideValidation()函数将在执行请求后设置 ngModel 的有效性.

The doServerSideValidation() function will set the validity of the ngModel after doing the request.

这篇关于如何让角度$ asyncValidator在模糊时触发但在输入时使用常规验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆