angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

dynamic element validation

Open hyusetiawan opened this issue 14 years ago • 235 comments

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?

hyusetiawan avatar Sep 21 '12 22:09 hyusetiawan

+1

michaelahlers avatar Oct 01 '12 19:10 michaelahlers

@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.

pkozlowski-opensource avatar Nov 20 '12 19:11 pkozlowski-opensource

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.

lobomuerto avatar Mar 21 '13 18:03 lobomuerto

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.

sinelaw avatar Mar 21 '13 23:03 sinelaw

+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/

langdonx avatar Apr 06 '13 04:04 langdonx

+1

robjames avatar Apr 08 '13 16:04 robjames

Faced this problem too.

yaroslav-ulanovych avatar Apr 16 '13 06:04 yaroslav-ulanovych

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.

yaroslav-ulanovych avatar Apr 18 '13 09:04 yaroslav-ulanovych

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.

kylebuch8 avatar Jun 04 '13 20:06 kylebuch8

+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.

seanzx85 avatar Jun 06 '13 21:06 seanzx85

+1 encountered this issue whilst creating dynamic forms.

kirkbushell avatar Jun 20 '13 00:06 kirkbushell

Is this already available in any angular build?

saurabhnanda avatar Jul 16 '13 08:07 saurabhnanda

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 avatar Jul 16 '13 08:07 saurabhnanda

@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 avatar Jul 16 '13 08:07 pkozlowski-opensource

@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?

saurabhnanda avatar Jul 16 '13 09:07 saurabhnanda

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/

thoersch avatar Jul 16 '13 15:07 thoersch

+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

vorburger avatar Jul 26 '13 00:07 vorburger

+1 -- this would be HUGE

shahzadc avatar Aug 14 '13 17:08 shahzadc

+1 it would be so huge

devmondo avatar Aug 15 '13 05:08 devmondo

+1 Need this fixed

veeracs avatar Aug 15 '13 19:08 veeracs