-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(select): prevent unknown option being added to select when bound … #11875
Conversation
…to null property If a select directive was bound, using ng-model, to a property with a value of null this would result in an unknown option being added to the select element with the value "? object:null ?". This change prevents a null value from adding an unknown option meaning that the extra option is not added as a child of the select element Closes angular#11872
I'm not sure this is right. On the surface, it looks okay, but the thing is, the unknown options are there for a reason (which is, when the model value is defined but doesn't match one of the specified options). I think this probably behaves as expected if the value is non-null, but it's inconsistent with the way ngModel normally works. |
I don't really think unknown options should be added for null model values. The value hasn't been defined if it's null. |
Yes, but this still violates the norm of ngModel, I'm not positive we want to do that. "null" does not mean "undefined", it means "null" |
urgh, this has failed a test due to an (i believe) unrelated timeout. |
@petebacondarwin what do you think, break the ngModel norm here or no? |
This change is trying to fix a problem that was introduced between 1.2.23 and now. I guess it's a regression. |
I was also worried about this change; The question is whether Looking at the code further I realise now that Here is a bit of a clearer plunker with regards the types of the models: http://plnkr.co/edit/Vc5ngCtdhzWwsQXcscKC?p=preview So I think we should merge this PR as in the case of a Can anyone spot a pain point in current applications from merging this? @caitp, @Narretz, @divercraig |
@divercraig - I just noticed that this behaviour has been the case even before 1.2.23. See http://plnkr.co/edit/Vc5ngCtdhzWwsQXcscKC?p=preview |
personally I think it's working as expected, but I don't care a whole lot if it is merged |
@divercraig - Here is a simple workaround that doesn't require us to make a potentially breaking change to the core, and which works for all recent versions of Angular 1.2, 1.3 and 1.4. |
@petebacondarwin I can see your "issue" in 1.2.23 which is weird because I only started noticing this problem in my project when I upgraded to 1.3.15 from 1.2.23. I acknowledge that there is a workaround, but I think if we think about it this change makes sense and is safe:
|
@divercraig - OK. I agree with you. The current behaviour, whether it is "correct" or not, is confusing and surprising. I'll land this PR this week. |
…to null property If a select directive was bound, using ng-model, to a property with a value of null this would result in an unknown option being added to the select element with the value "? object:null ?". This change prevents a null value from adding an unknown option meaning that the extra option is not added as a child of the select element. Since select (without ngOptions) can only have string value options then `null` was never a viable option value, so this is not a breaking change. Closes #11872 Closes #11875
…to null property If a select directive was bound, using ng-model, to a property with a value of null this would result in an unknown option being added to the select element with the value "? object:null ?". This change prevents a null value from adding an unknown option meaning that the extra option is not added as a child of the select element. Since select (without ngOptions) can only have string value options then `null` was never a viable option value, so this is not a breaking change. Closes angular#11872 Closes angular#11875
…to null property
If a select directive was bound, using ng-model, to a property with a value of null this would
result in an unknown option being added to the select element with the value "? object:null ?".
This change prevents a null value from adding an unknown option meaning that the extra option is
not added as a child of the select element
Closes #11872