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.
When using $removeControl to remove a nested ng-form, the inner form still holds a reference to parentForm, (specifically those 3 methods: $setValidity, $setDirty and $setSubmitted). So, when the validity state of the nested (isolated) form changes, it will also affect the parentForm, even though it was removed.
Suggested Fix
In above mentioned methods, add if(parentForm[form.$name]){/*do*/} before changing parentForm to check if it still holds a reference to the nested form/control
The text was updated successfully, but these errors were encountered:
Honestly I'm not sure why those two methods are even public. :)
Those methods are very confusing as public API because the truth is you cannot just add an input control to any form control you like, the input control is pretty much bound to it's parent form forever.
The way I see it, $addControl and $removeControl should be private and instead we should expose $enableControl and $disableControl that let users ignore and un-ignore validity/dirtiness of child controls without actually removing or adding them as child controls.
But I guess this is too much of a change right now... Anyway, I'm looking into this.
I looked at this with @IgorMinar and @tbosch and we decided that there's no reason to use these APIs to do this. It's better to just destroy/recreate the relevant forms.
When using
$removeControl
to remove a nestedng-form
, the inner form still holds a reference to parentForm, (specifically those 3 methods:$setValidity
,$setDirty
and$setSubmitted
). So, when the validity state of the nested (isolated) form changes, it will also affect the parentForm, even though it was removed.Here is a Demo
http://plnkr.co/edit/uiUjwB?p=preview
Occurences of
parentForm
referenced in nested form/controladdSetValidityMethod
FormController.$setDirty
FormController.$setSubmitted
Suggested Fix
In above mentioned methods, add
if(parentForm[form.$name]){/*do*/}
before changingparentForm
to check if it still holds a reference to the nested form/controlThe text was updated successfully, but these errors were encountered: