Forms in AngularJS sometimes can become a bit ugly. That's my case. I have seemingly simple structure of three forms. Two of them should be related to each other, while third should be completely separate.
<form name="foo">
<div ng-repeat="f in foo.list">
<custom-component ng-form="foo['f_'+$index+'_something']"></custom-component>
</div>
</form>
Above is main form. It binds some part of itself to custom component.
The component on the other hand has two forms inside:
<div ng-form="$ctrl.form">
<!--foo-->
</div>
<some-popup>
<div ng-form="$ctrl.popupForm">
<!--foo-->
</div >
</some-popup>
The problem is that popupForm
is somehow automatically bound with other forms. The result is far from expectations. When I modify popupForm
it makes item on foo
form dirty. Moreover if some field on popupForm
doesn't meet validation criteria, and popup is closed then error is propagated to the foo
form's item. The latest problem can be solved with ng-if
directive used to "remove" popupForm
from DOM when popup is hidden, but it still not complete solution.
It there any way to make a form (popupForm
of the example) completely separate from other? Can I prevent nesting forms somehow?