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

Bug in angular.FormController when nesting ng-form's #9035

Closed
Joel-Kornbluh opened this issue Sep 11, 2014 · 2 comments
Closed

Bug in angular.FormController when nesting ng-form's #9035

Joel-Kornbluh opened this issue Sep 11, 2014 · 2 comments

Comments

@Joel-Kornbluh
Copy link

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.

Here is a Demo
http://plnkr.co/edit/uiUjwB?p=preview

Occurences of parentForm referenced in nested form/control
addSetValidityMethod
FormController.$setDirty
FormController.$setSubmitted

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

@shahata
Copy link
Contributor

shahata commented Sep 12, 2014

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.

@btford
Copy link
Contributor

btford commented Oct 8, 2014

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.

@btford btford closed this as completed Oct 8, 2014
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.

4 participants