You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
The idea is to force a form to call $validate() on all its controls. Where this is useful is when the validity of a form control depends on the values of other controls in the form.
My current workaround is this:
function revalidate(form)
{
angular.forEach(form, function (value, key)
{
if (typeof value === 'object' && value.hasOwnProperty('$modelValue')) value.$validate();
});
}
The text was updated successfully, but these errors were encountered:
I think validating all controls just to capture any a specific dependency might be an overkill.
I agree there should be an easy way to specify that an element's validity depends on values other than the input value. (But that should be on a per-control basis imo.)
True. In my use case I had a large number of controls (generated with ng-repeat) that needed to be revalidated when any of those changed. These controls represented the majority of controls in the form, so it made sense for me to revalidate the entire form.
I want to share another possible use-case for this feature:
Lets suppose form has nested forms (i.e. created by ng-repeat) which several fields which validation depends on other model or these fields have $asyncValidators (i.e. user name should be unique in application).
Use-case: When user changes such field it is become valid and then before he submits form something has changed on server. On submit server response we get info that something become invalid and in that moment we need to call $validate().
Or, as more generic way, it would be nice to have #14749 feature and also ability to iterate through nested forms. Then we can easily make any other application specific logic as well as validation.
Narretz
added a commit
to Narretz/angular.js
that referenced
this issue
Jun 15, 2018
The idea is to force a form to call
$validate()
on all its controls. Where this is useful is when the validity of a form control depends on the values of other controls in the form.My current workaround is this:
The text was updated successfully, but these errors were encountered: