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?
is there a way to modify the decorator so the $name value tracks a dynamic name for an ngForm? Ive got a bunch of nested ng-forms and id like to be able to discriminate which are invalid from the parent form's $error object. is there another way to do this? As is, dynamic name sticks in the attribute but $name references the pre-interpolated val
+1
@idiotslowdown if u have nested ng-forms, u can check the errors of each one using the form name
<ng-form name="myForm1">
<ng-form name="myForm2">
<div ng-class="{'has-error': myForm2['myinput1'].$invalid}">
//form element with dynamic name "myinput1"
</div>
</ng-form>
</ng-form>
console.log($scope.myForm2.$valid)
console.log($scope.myForm1.$valid)
I had no problem at all using dynamic names and nested forms (with the decorator ofc)
Here this is what I mean: http://plnkr.co/edit/icbjmZEJtzmey4TFJ9WQ?p=preview
Each failure returns $name: "{{subitem.tag}}". It would be nice to retrieve the names of invalid forms from the parent error object, while remaining agnostic to the form names themselves ahead of time
@idiotslowdown I see it now, if u inspect the var $scope.itemForm u will see {{subitem.tag}} instead of the var for each nested form. The solution in the decorator above is for dynamic input names, not for dynamic form names. If you want to do that i'm afraid you'll have to get the html with the form names pre-rendered from the backend
+1
+1
+1
+1
+1
+1, I would love to see this fixed.
It would've saved me a lot of time in my "in the deep end" Angular learning process!
+1
Had the same problem. I spent a few days researching and think found a solution. I put a 'ng-form' inside the 'ng-repeat'. Using the name 'ng-form' and name input in directive 'ng-show', the angular can differentiate the input names, eliminating the problem of validation. =)
http://jsfiddle.net/8JzDb/148/
Hello, I've created a directive to fix this. I hope this helps.
var ngNameDirective = ['$interpolate', function ($interpolate) {
return {
priority: 9999,
controller: ['$scope', '$attrs', function ($scope, $attrs) {
var interpolatedName = $interpolate($attrs.ngName)($scope);
if (interpolatedName) $attrs.$set('name', interpolatedName);
}]
};
}];
Using ngName directive instead of name attribute you can register form-controls (ngModels) and sub-forms (ngForms) dynamically.
+1
It's f****g ridiculous that animation got hundreds of improvement (according to changelog) and we are unable to cleanly, properly render a dynamic form in angular. I'm starting to feel that it was a very bad choice 1.5 years ago to build a large enterprise application on top of this framework...
@dropout that's a bit melodramatic. You can get this behaviour to work, it's just not "out-of-the-box". Might have to do some real work. Shock, horror, gasp!
@kirkbushell This is not a melodrama, this is the 2978934 nth fix and workaround I'm applying because it fails to prove under large scale. And it's harder to maintain these fixes and workarounds when you switch to a newer version number. You know it's enterprise development not javascript zoo...
@dropout sorry, but you must be doing it wrong. I've been running a large application for nearly 18 months, from angular js 0.6 and despite the initial cost of making it work, it hasn't failed since.
@kirkbushell I wonder how large this application is if you can maintain it yourself.
@kirkbushell @dropout seriously is there a good reason why this is being overlooked it's getting absurd the number of comments against this issue.