Form control is overridden when nesting with ng-form and ng-repeat #10165
Comments
It would definitely make the api / code more complex. Why are you creating a new form anyway if you only have one input in it? |
Just to keep the example short :-) |
Looking at both w3c documentation (http://www.w3.org/MarkUp/html3/forms.html) and the HTML5 proposal (http://www.w3.org/TR/2011/WD-html5-20110525/forms.html#the-form-element). Both state that a form element should not have child elements that are forms.
So I guess you can expect odd behavior from this as it isn't really an expected use case. |
@jrmiddleton: @hanneskaeufler: That said, I don't find it that ugly to use the Maybe, you could keep things more readable by using
|
Hey @gkalpak, I like the |
I'd love to see nested forms used in We use server-side validation in our app and the validation contexts reference the controls using something like |
I Updated the Sample |
I've just run across this issue. It appears this worked at one point as recently as last March via http://stackoverflow.com/questions/22248733/angularjs-form-validation-within-ng-repeat. The |
@abobwhite, can you provide a demo of what is not working ? |
+1 I'm looking for this for a while now. Would be great if a syntax like this would be supported:
|
I just found a good temporary solution in here: #1404 |
Is it possible that nesting |
I'm going to close this, since we are not likely to change the current behavior and it is already possible to have something very similar to the requested. In addition to the above mentioned solutions, you could even have a array-ish object by using a wrapper <form name="categoryForm">
...
<ng-form name="tags"><!-- Wrapper `ngForm` to collect all tags -->
<div ng-repeat="item in items">
<ng-form name="{{ $index }}"><!-- Use `$index` as the key, so tags can be accessed by index -->
Tag name: <input name="name" ng-model="item.name" required />
<div ng-if="categoryForm.tags[$index].name.$invalid">This is great from the inside !</div>
</ng-form>
</div>
</ng-form>
</form> Caveats:
@piyushchauhan2011, yours sounds like a general support question. Please, use one of the appropriate support channels for these types of questions. |
Say I have a form which creates nested forms via
ng-repeat
andng-form
.This is great for accessing the form control
tags.name
inside theng-form
block. But from the outside, say in the controller, there is no way to get the same control.$scope.categoryForm.tags
is always set to the last control created by the repeatedng-form
.See http://plnkr.co/edit/SvBAxJFioTIgfs7Wvvk1?p=preview
It seems
$scope.categoryForm.tags
should rather be an array ofFormControllers
or something instead of only the last FormController.Currently this has me creating ugly workarounds like
which is possible since #1404 got closed.
Could we support something like an array of
FormControllers
or is this creating any other problems I´m not thinking of?The text was updated successfully, but these errors were encountered: