Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

ng-form in ng-repeated tabs #1216

Closed
djabor opened this issue Oct 30, 2013 · 4 comments
Closed

ng-form in ng-repeated tabs #1216

djabor opened this issue Oct 30, 2013 · 4 comments

Comments

@djabor
Copy link

djabor commented Oct 30, 2013

When trying to generate multiple forms in tabs, using ng-repeats, there seems to be a collision of 2 separate bugs (1 on angularjs side, the other on ui.bootstrap (0.4.0 and 0.6.0))

  1. to have form input validation within ng-repeat, one is required to use ng-form for each repeated element to keep the validation

  2. using ng-form directive on tab directive breaks ngform with the

Error: [$compile:ctreq] Controller 'form', required by directive 'undefined', can't be found!

message.

Trying to fix this via #524 which, on the surface seems like the same issue, is of no help and creates an additional error of an orphaned item not being able to transclude.

@pkozlowski-opensource
Copy link
Member

@djabor could you please provide a minimal reproduce scenario using http://plnkr.co/ ?

@djabor
Copy link
Author

djabor commented Nov 9, 2013

The first plunkr is the initial version of the repeatable tabs directive, which contains a form within each tab.
The tabs are dynamically created (which is not relevant for this issue, but makes the context of this setup a bit clearer).

http://plnkr.co/edit/YiOLU586fglrHM0a2ws0?p=preview

If you run it, you will notice that the $dirty flag of the form won't change to true when editing inputs within the tabs (fields A and B), it will, however, change when the general field is changed.

This is expected 'buggy' behavior from angular as described extensively (for example here: angular/angular.js#1404)

The working fix is to wrap each ng-repeated input within an ng-form directive to enable nested forms and propagate changes to the wrapping controller.
This can be seen working here:

http://plnkr.co/edit/pg2NJSdoF1JPmHmdpRnP?p=preview

When adding the ng-form directive to the tab within ON the ng-repeated tab element or within it, will cause the error i mentioned before because the ui-bootstrap tab directive is isolated and effectively disconnects the form/ng-form

@pkozlowski-opensource
Copy link
Member

@djabor I've just tested with the latest AngularJS version and the latest code from this library and it looks like things are in order now: http://plnkr.co/edit/6oUOfKgeLBZBX2u0PrZY?p=preview

Your example is rather big so I'm not 100% sure if I'm testing the right thing. Could you please check on your end if things work as expected? If not, could you please try to trim down the reproduce scenario?

@pkozlowski-opensource
Copy link
Member

@djabor haven't heard from you so going to close this one for now. Feel free to re-open if this is still an issue for you and you've got a reproduce scenario.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants