-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Multiple inputs with the same name bug #7647
Comments
Related to #3345 --- I'm not sure I completely buy @pkozlowski-opensource's suggestion to not use the same name, because this is actually how browsers kind of need to work, in order to select the right control --- it works in angular, but it's a huge hack, and we shouldn't need to instantiate multiple ngModels which need to be shared anyways. This probably should be fixed, but it might need to wait for @matsko's refactoring (but, in case this won't be fixed, you can use the workaround which requires you to specify different names, but the same ng-model value, for each input --- and not have $pristine be represented consistently for each one) |
Maybe the better idea is to create a shared controller for all inputs within a single group. This way we will be able to check state of the concrete input or of the entire group, like this:
|
Also, @pkozlowski-opensource's solution will not work properly if |
Do you know what? I think what we need to do is implement a Let's implement |
…that become dirty and stay valid. We need so emit an event for the 'showSuccess === true' case. We also check the dirty state on the ngModelCtrl for this element instead of the ngModelCtrl on the scope, see angular/angular.js#7647.
I'm not a big fan of radioGroup directives or contructs in general, because they don't go along well with how HTML works. Coul we cook up something that does the grouping internally? Or exposes an extra radioGroup controller? |
When you have multiple input fields with the same name, like radio buttons for example, you are getting one
ngModel
controller for each input. But, when you addressing this field by name, like this:formName.fieldName
, you are getting a reference to the lastngModel
controller.The problem is that this controllers doesn't know about each other and do not coordinate their state. And from the user perspective they must have a shared state.
>> The bug is illustrated here <<
In the provided example, I'm trying to detect pristine state of the gender radio field, but I'm getting incorrect result, since I'm getting pristine state not of the entire radio group but only of the last radio button in the group.
From the end-user perspective this can be considered a real bug.
As a solution to this problem, maybe we should use a single
ngModel
controller for all inputs with the same name, or probably better, to synchronize the state ofngModel
s from the same group, so properties like$pristine
would be consistent.The text was updated successfully, but these errors were encountered: