-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ngModel renames inputs with no "name" attribute to "undefined" #9707
Comments
+1 for the proposed fix An input with no name shouldn't end up on the formController object |
Hi @rodyhaddad! Here in http://ngeurope.org/ Should we check for the existence of a name before adding the control in |
@Puigcerber This would be a breaking change: currently, the control is added to the form regardless of name, but it is only published on the form when a name is set: angular.js/src/ng/directive/form.js Line 122 in b1ee538
It's a little weird. |
@Narretz I think this code was introduced when the $setPristinemethod was added. You need to have the So yeh, it is not that weird :-) |
I talked with @Puigcerber in person at ngeurope, he's currently investigating why See Lines 2304 to 2309 in 89c57a8
|
Hi @rodyhaddad! I checked it but |
I left a line note about this, but perhaps should have just made it a comment, so I've copied it here for anyone else who runs into this problem: With 531a8de, if anyone was using |
The following Plunker illustrates the issue (see the console output).
http://plnkr.co/edit/lZEgQv05Dm7YGelXZDhg?p=preview
When an input uses the ng-model directive, the following code watches for the "name" attribute to change.
src/ng/directive/input.js:2456
introduced: 729c238
modified: b1ee538
The problem is that this observer fires with
undefined
if the input doesn't have a "name" attribute, causing the control to be renamed toundefined
. If multiple inputs are missing the "name" attribute, they are all renamed toundefined
, and overwrite each other in theformCtrl
object.I propose a fix:
And a test that fails before the fix and passes after the fix:
I'm happy to submit this as a PR, but I wanted to file an issue first to confirm that this is unexpected behavior, and that my fix looks OK.
The text was updated successfully, but these errors were encountered: