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?
@dropout I never said I was the only maintainer.
@digitalgym not sure tbh, seems like a likely candidate for a fix/feature addition.
I think the subform validation should have some options where we can set all elements of a subform being pristine not to trigger an invalid form error even if some of these subform fields are required.
I am thinking to develop a very large applciation in angularjs, i love it, it is fun, fast easy and complicated at the same time.
I cant wait to @dropout and @digitalgym having some number line of code argument.
@dropout, there is a solution to this subform dynamic name fix a bit eralier in the comment. You just have to modify your app.config, and add some $provides, to override the default angular behavior concerning inputs dynamic name, so you can have
<input name="firstname_{{i}}">
into a ng-repeat.
here is the link : http://jsfiddle.net/Thinkscape/23RPt/
It's been a few months since I came up against this issue so my memory is a little hazy however here's my problem.
I have a form that has 'add another' functionality that dynamically adds new fields (3 fields) to a form, I also have an x to remove the fields. I want to access each 'subform' in a controller to perform validation actions based on the data provided by the user.
Some of the hacks in this thread have enabled me to add the new fields, but the names/indexes don't get updated upon delete so then the validation gets applied to the wrong fields, and I haven't found a way to access the inner forms individually in the controller to validate them.
Angular has a 'dynamic html' philosophy, but (unfortunately) it doesn't seem to extend to forms (yet).
nested ng-form solves that issue.
I'm pretty sure I tried that, iirc I couldn't access the nested forms in the controller (or didn't know how to). I'll have to put together a demo repo as my use case seems to be a little more advanced than the others I've seen.
If you need to access it via controller, that can get tricky. We had to do a combination of directives and shared controllers to manage the fields and forms. Depends on what your'e trying to do. If it's just validation, you should be able to use the built-in angular (or your own custom validation rules) to manage that.
@kirkbushell Excuse my ignorance, you've written "I've been running" not "maintaining"
To all the others having problems rendering complex dynamic forms against remote async validations, server generated access controlled configurations etc... my advice if you are about to start something like this roll your own thing, don't try to use angular forms and validation facilities for this because it's pretty immature and causes more problems than it solves... this whole damn thread speaks for itself
@dropout you inferred on your own that I was a lone cowboy, I've corrected you with clarification. Case closed. Even without that, your implication with your statement was rather rude, rather than just asking ;)
And must disagree with dropout, as we've been able to get it going since earlier angularjs versions. Don't spread lies @dropout simply because you've had certain difficulties. We had our earlier problems, and as I said earlier it certainly does require some custom work, but it's possible, and it'll work once setup correctly.
It would be good, however - to have this baked into the codebase.
@kirkbushell I'm not spreading lies it's my opinion. Sorry about that.
+1
+1
@Rafa-GdA Sorry for my ignorance, but how can I use your directive? I don't realize how to implement your code as a directive into my code.
Can you help me? Thanks.
@rodrigok Here's a fiddle with an example: http://jsfiddle.net/y3YJk/ And here another fiddle with the first post example using the directive: http://jsfiddle.net/8JzDb/149/
Thank you @Rafa-GdA
+1
+1
+1
This appears to be the leading workaround: http://plnkr.co/edit/hSMzWC?p=preview
Are there any pitfalls or gotchas I might need to be aware of?
+1
I'm not sure of the exact details of the gotcha.
@matsko has said that they do this differently in AngularDart for some reason, because apparently it's easier to nest child forms underneath and do dynamic validation that way. But honestly, I don't really get why that's any simpler or easier to manage than this one. I've yet to encounter the pitfall with this approach.
+1 after spending hours and hours trying to debug what i'm doing wrong, looks like it's a pretty popular pain point for the community ;). Hope to see a fix soon.