PolymerElements / iron-selector

Manages a list of elements that can be selected
32 stars 55 forks source link

Value of 0 returns a null #39

Closed SleepyMan closed 8 years ago

SleepyMan commented 9 years ago

When selectable invokes _valueForItem, it gets the value, but it tests for falsy values at line 239:

_valueForItem: function(item) {
  return item[this.attrForSelected] || item.getAttribute(this.attrForSelected);
},

This removes the ability to set the attribute to 0, as it would fail the first test (item[attr]), and go for the second one (getAttribute), which returns a null, thus becoming unselectable (while visually selectable in the case of paper-radio)

Example:

<paper-radio-group on-paper-radio-group-changed="log">
  <template is="dom-repeat" items="[[someItems]]">
    <paper-radio-button name="[[index]]">[[item]]</paper-radio-button>
  </template>
</paper-radio-group>

Using paper-radio-group and repeating template, if I were to set the name (value) of the paper-radio-button as its index (first button would be 0, second would be 1, etc.), then the first one would seem selectable, but when reading the selected attribute, it would be null, as if nothing was selected, while the others would be ok. It does fire the "paper-radio-group-changed", but with a value of null.

Changing the offending line, allows to set indexes as values correctly.

Gwalks91 commented 8 years ago

+1 I am also having this issue and was wondering if any progress has been made on it?

notwaldorf commented 8 years ago

@SleepyMan Any interest in sending a PR to fix this? :)

arthurevans commented 8 years ago

I just ran across this the other night looking at an issue someone else reported, and came to the same conclusion as @SleepyMan... I can do a PR.

arthurevans commented 8 years ago

Sent. Consider if you will.