Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

[feature request] request adding $validate() method on FormController #14517

Closed
jrharshath opened this issue Apr 26, 2016 · 3 comments · Fixed by #16601
Closed

[feature request] request adding $validate() method on FormController #14517

jrharshath opened this issue Apr 26, 2016 · 3 comments · Fixed by #16601

Comments

@jrharshath
Copy link

jrharshath commented Apr 26, 2016

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();
            });
        }
@gkalpak
Copy link
Member

gkalpak commented Apr 28, 2016

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.)

@jrharshath
Copy link
Author

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.

@adubadzel
Copy link

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
Narretz added a commit to Narretz/angular.js that referenced this issue Jun 15, 2018
Narretz added a commit that referenced this issue Jun 18, 2018
Narretz added a commit that referenced this issue Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants