Ember-power-select: select does not like options value containing raw numerical zero

Created on 9 May 2016  路  8Comments  路  Source: cibernox/ember-power-select

The input selector acts wiggy when you define it to have an option element that is the number 0.

For instance.

timeZones: [-11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
timeZone: 0,

{{#power-select options=timeZones selected=timeZone searchEnabled=false onchange=(action (mut timeZone)) as |opt|}}
                    {{opt}}
{{/power-select}}

What happens is that the selection is not displayed if the selected is set to 0 and also when you scroll to the selection in the UI it auto-scrolls back to the top of the window.

bug

Most helpful comment

yeah, I'm sure there is at least a couple places where I'm checking something like
if (selectedOption) { do foo } where I should do if (selectedOption !== undefined) { do foo }.

In my opinion, 0, false and null are perfectly valid options. The only value that should represent the absence of an option, is undefined

All 8 comments

Curious edge case. Can you create a PR with a failing test(s)?

Done.

I wasn't able to test the scroll behavior but i think that is a byproduct of the components inability to select the option itself.

FYI the work around for this issue is to use quoted "0". This appears to work properly.

yeah, I'm sure there is at least a couple places where I'm checking something like
if (selectedOption) { do foo } where I should do if (selectedOption !== undefined) { do foo }.

In my opinion, 0, false and null are perfectly valid options. The only value that should represent the absence of an option, is undefined

I can reproduce the same unselected behavior with false as the value

@cibernox any updates to this? still able to replicate this behavior.

+1

I don't have much time to work on this, but if someone wants to tackle I'd be happy to assist. I think that it should be supported.

In the meanwhile, you can use strings.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jorkas picture jorkas  路  8Comments

luketheobscure picture luketheobscure  路  10Comments

davelowensohn picture davelowensohn  路  4Comments

Kilowhisky picture Kilowhisky  路  6Comments

Blackening999 picture Blackening999  路  3Comments