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 was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
[feature request] request adding $validate() method on FormController #14517
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();
});
}
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.
Activity
gkalpak commentedon 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 commentedon Apr 28, 2016
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 commentedon Jan 18, 2018
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.
feat(form.FormController): add $getControls()
feat(form.FormController): add $getControls()
feat(form.FormController): add $getControls()
feat(form.FormController): add $getControls()