Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Issues when using values '' and false #1328

Closed
fiznool opened this issue Nov 27, 2015 · 4 comments
Closed

Issues when using values '' and false #1328

fiznool opened this issue Nov 27, 2015 · 4 comments

Comments

@fiznool
Copy link
Contributor

fiznool commented Nov 27, 2015

I have a bunch of items as so:

scope.items = [{
  label: '-- None Selected --',
  value: ''
}, {
  label: 'Yes',
  value: true
}, {
  label: 'No',
  value: false
}];

scope.model = '';

My HTML:

<ui-select ng-model="model">
  <ui-select-match>{{ $select.selected.label }}</ui-select-match>
  <ui-select-choices repeat="item.value as item in items track by item.value">{{ item.label }}</ui-select-choices>
</ui-select>

I'm expecting when the select box loads up to see the --None Selected-- item, since my model is set to the empty string, ''. However, due to this line using a double equals instead of a triple equals, the No item is actually displayed, since the formatter traverses from the end of the items array to the beginning, and when it finds the item with the false value, it compares false == '' which returns true.

Is there any historical reason why this is a double equals instead of a triple equals? Would you accept a PR which changes this to triple equals?

@wesleycho
Copy link
Contributor

Can you post a reproduction via Plunker just for assistance with debugging for anyone who wants to look at this closer?

This does sound like an issue though.

@fiznool
Copy link
Contributor Author

fiznool commented Mar 28, 2016

Here is a plunkr showing the issue.

http://plnkr.co/edit/XosVjr?p=preview

@user378230
Copy link
Contributor

The suggested fix appears to work in plunkr, will also need a test though.

@fiznool can you put together a PR?

fiznool added a commit to fiznool/ui-select that referenced this issue Apr 16, 2016
Use triple equals to determine if the selection matches
one of the choices.

Fixes angular-ui#1328
fiznool added a commit to fiznool/ui-select that referenced this issue Apr 16, 2016
Use triple equals to determine if the selection matches
one of the choices.

Fixes angular-ui#1328
@fiznool
Copy link
Contributor Author

fiznool commented Apr 16, 2016

@user378230 submitted a PR.

fcaballero pushed a commit to fcaballero/ui-select that referenced this issue Apr 17, 2016
Use triple equals to determine if the selection matches
one of the choices.

Fixes angular-ui#1328

fix(indentation)  use 2 spaces, no tabs

fix(indentation)  use 2 spaces, add white-space
fcaballero pushed a commit to fcaballero/ui-select that referenced this issue Apr 25, 2016
Use triple equals to determine if the selection matches
one of the choices.

Fixes angular-ui#1328
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants