-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(input): allow templates on the name
attribute of an <input>
#3135
Conversation
Handle the `name` attribute on an <input> as a template
@pkozlowski-opensource I think that a form field should not be dynamic as it adds some undesirable side-effects and comes at a cost (even if this makes this less flexible). E.g.
#2988 handles this by making |
@lgalfaso so, clearly people are after dynamically generated names. But introduction of dynamic names creates interesting corner cases. For example, given the HTML: <input type="text" name="{{alias}}" ng-model="value" required/>' I could have the <span ng-show="form[alias].$error.required">Required!</span> could still be confused... |
@pkozlowski-opensource Agree, but it was a conscious decision not to allow A minor side-effect is that we do not have to watch for changes on the value, so we would save a few cycles here and there |
I've been playing around with this fix a bit, and came across this scenario that doesn't seem to work. Is this a bug? it('should support dynamically generated input names', function () {
scope.names = ["input1","input2"];
doc = $compile(
'<div ng-form="myForm">' +
' <input type="text" ng:repeat="n in names" name="{{n}}" ng-model="n"/>' +
'</div>')(scope);
expect(scope.myForm.input1).toBeDefined(); // Fails
expect(scope.myForm.input2).toBeDefined(); // Fails
}); One-off aliasing is great, but most of the time I want to generate my inputs dynamically. |
@Kleptine ng-repeat is implemented async, so at your test, after |
Ah, of course. Looks good then. |
+1 |
+1 |
+1 |
1 similar comment
👍 |
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
This was implmented in 729c238 |
Handle the
name
attribute on an<input>
as a template