PolymerElements / iron-selector

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

How do you clear the current selection so that no items are selected? #54

Closed miztroh-zz closed 8 years ago

jodekirk commented 9 years ago

I don't know if there's a clear() function, but setting the selectedItems and selectedValues to [] seems to work. For example if you have an iron-selector with id="selector": this code clears the selected items. this.$.selector.selectedItems=[]; this.$.selector.selectedValues=[];

jodekirk commented 9 years ago

oops. I swear that code worked the first couple times I tried in the Chrome 64 Dev browser, but now I'm getting console errors: Uncaught TypeError: Cannot set property selectedItems of # which has only a getter

arthurevans commented 9 years ago

See the doc here:

https://elements.polymer-project.org/elements/iron-selector?active=Polymer.IronMultiSelectableBehavior

selectedItems is read-only. selectedValues is read/write. Setting that should clear the selection.

Note that selectedValues doesn't reflect, so if you're looking at the element in the inspector, and selectedValues was set to a literal array in markup, you'll see the original value on the attribute (like, selected-values="[1,3]") in the DOM tree. This isn't a problem and it doesn't affect data binding or anything else -- I just mention it because it's a potential source of confusion.

cdata commented 8 years ago

I believe that this issue has been resolved. Please re-open if it is still unclear how to clear the selected items!