In AngularJS, how to force the re-validation of a field in a form when another value in the same form is changed?

冷暖自知 提交于 2019-12-05 11:34:25

I have done the same thing for validation of start-date on change of end-date. In the directive of start-date add watch for change of end-date and then call ngModel.$validate() in case end-date new value is defined.

    scope.$watch(function () {
        return $parse(attrs.endDate)(scope);
    }, function () {
        ngModel.$validate();
    });

The important part to take is call to ngModel.$validate() inside the directive.

Note you should use $validators for custom validations above to work. read here, $parsers is the old way - from angularjs 1.3 use $validators

FIXED PLUNKER LINK

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!