dynamic element validation
I have a problem with validating inputs that are generated dynamically. Here is the fiddle that shows the problem: http://jsfiddle.net/flsilva/8JzDb/17/
this is taken from: https://groups.google.com/forum/?fromgroups=#!topic/angular/qLeUWZVuQMI
the name is generated fine but it's not bound to the form scope. Because I can name it correctly but the form is not bound, it seems that this behavior is inconsistent.
Thoughts?
+1
@hyusetiawan @michaelahlers In the current version of AngularJS you need to use nested ng-form directives (http://docs.angularjs.org/api/ng.directive:ngForm) to validate dynamically generated input fields.
Here is a fixed jsFiddle: http://jsfiddle.net/6H8Xx/ and another example: http://jsfiddle.net/pkozlowski_opensource/rqARD/1/
Closing for now, please feel free to reopen if you've got any further questions / issues with this one.
I really don't think this issue should be closed. The "solution" (using nested forms) seems more of a hack than a proper design pattern. Nested forms are... untidy. I'm trying to resolve the same problem with dynamic elements generated via directives, to no avail; I need my original form to be aware of its own elements.
I agree - this issue should be re-opened and only closed when a proper solution is introduced in Angular. It would make sense to have something like a "ng-name" directive that allows setting the name from an expression.
+1
Here's a modified fixed jsFiddle that will let the parent form still submit properly (the escaping makes it pretty nasty): http://jsfiddle.net/langdonx/6H8Xx/2/
+1
Faced this problem too.
I tried to fix that, but looks like they're already moving in that direction: now attributes are interpolated before directives are linked, so ng-show from the fiddle watches the correct value. The only thing left is to assign a name to a control not in NgModelController but in ngModelDirective, that's one line fix.
I also think that nested forms is going to solve this. If you have a nested form that has radio buttons in it that don't use a dynamic name attribute, you'll run into some issues with selecting the radio buttons.
+1 Users are building forms and then having other users submit data through those generated forms. We need dynamic element binding for forms. I have written entire custom validation for our forms currently, but out of the box functionality would be nice. Nesting ng-form does seems pretty messy for us since every field would have to be wrapped.
+1 encountered this issue whilst creating dynamic forms.
Is this already available in any angular build?
Also, if this is not already in a build, what's the exact solution using nested ng-forms? As-per the documentation ng-form names are also not interpolated.
@saurabhnanda no, there is no fix in master yet. There are several PRs opened but those need careful review. The current solution is to use the ngForm directive as described here: http://stackoverflow.com/a/12044600/1418796
@pkozlowski-opensource -- if one uses the solution given at http://stackoverflow.com/a/12044600/1418796 how can one access the nested forms in the outer controller's scope? It wouldn't be possible, right?
The "work around" doesn't seem to work on all cases. Radio groups fail on this as the newly applied scope doesn't adhere to them. Here's an example:
http://jsfiddle.net/sEnhs/1/
+1! it would be great to see this fully supported.. current (1.1.1) nested forms doesn't seem to really work for input type, see e.g. my http://jsfiddle.net/vorburger/8CxRC/7/ for http://stackoverflow.com/questions/17841915/angularjs-ng-model-form-driven-by-ng-repeat-over-ui-model-description-data-how-t
+1 -- this would be HUGE
+1 it would be so huge
+1 Need this fixed