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?
I'd be happy to. Is there anyplace that this is documented? I can't seem to find any clear definition of what the final implementation supports (in terms of syntax). Is there a working example somewhere?
it's not documented anywhere, it's just the expected behaviour which is consistent with the way the framework actually works. The fact that it didn't work before was surprising to people.
The syntax is just interpolated strings, eg name="{{custom}}FormControl" or similar. This didn't used to work the way people expected, now it does, consistent with the rest of the framework.
I guess you've found that there is some documentation that it does not support this, so it would be good to remove or rewrite it to indicate the current behaviour.
Thank you. Yes, minimally it should be removed. An example (maybe not here ... but with ng-repeat?) would be helpful.
For example, how do you reference this in something like ng-messages?
ng-messages="myForm.{{custom}}FormControl.$error"
does not work.
Interpolated paths in ngMessages is a different problem, although it could certainly receive a similar fix.
@DeborahK maybe you van just use ng-messages="myForm[custom + 'FormControl'].$error"
+1 on this issue. Being able to pass name arguments to directives as part of their isolate scope would make life much easier.
Currently having to hodge : http://stackoverflow.com/a/25652866 into every application that requires dynamic validation and it just feels hacky.
@scouser3008 this issue was fixed, you don't need to decorate ngModelController at all now. The name attribute is interpolated now.
@caitp Yup, completely my fault flagging this. For IE compatibility I'm having to use v1.2 and got caught up in debugging! Apologies.
@caitp I wish I found this thread a year ago when I first had this issue. I used the ng-form hack. Unfortunately, this hack does not work when your dynamic forms that are being repeated several times have radio buttons... because even though the form validation "works", now all of your radio buttons are part of the same radio group and so you can only select 1 on the entire page of forms. But I digress...
We are stuck on 1.2.x for the moment and so my question is, did @Thinkscape 's decorators (found above) prove to be as effective as the eventual solution that is implemented in 1.3.x?
@spencerb02 you mean the decorators from my plunker? :p
So, the stuff that was merged into 1.3.x has some extra meat to it. In particular, it will remove controls from the form controller and re-add them if the interpolated value changes, and the goal is to remove them when they are destroyed, too.
The decorators just interpolate one time, so it can cause problems during ngRepeat if an $index changes, for instance.
@caitp excellent. Thank you. Forgive my naivety, but when would indexes change that wouldn't also be a redraw? Also, if I have another unique key to tie it to rather than $index, this won't be an issue, right?
@spencerb02 it's not exactly that simple, if the form is outside of ngRepeat, and the length changes, you can still have stale stuff in the form --- during a redraw, if an element is moved, it is not re-transcluded. http://plnkr.co/edit/rRYgWgdo4M9sUnGiNwqv?p=preview << so, the controller wouldn't be re-created, and it wouldn't create a new scope, just the scope values would change.
+1
+1
+1
+1
+1
+1
+1
+1