Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Multi-pre-select from template is either impossible or not documented #28

Open
codekrolik opened this issue Dec 21, 2016 · 4 comments
Open

Comments

@codekrolik
Copy link

codekrolik commented Dec 21, 2016

Description

Multi-pre-select from template is either impossible or not documented.
In order to do multiple preselect "reinventing bycicle" through writing custom item populating code is required.

Expected outcome

Should be able to do something like

<paper-listbox multi>
  <paper-item selected>Item 1</paper-item>
  <paper-item>Item 2</paper-item>
  <paper-item selected>Item 3</paper-item>
</paper-listbox>

Actual outcome

The only documented way which doesn't support multiple select (or if it does, that part is not documented at all)

<paper-listbox selected="0">
  <paper-item>Item 1</paper-item>
  <paper-item>Item 2</paper-item>
</paper-listbox>

Live Demo

https://elements.polymer-project.org/elements/paper-listbox?view=demo:demo/index.html&active=paper-listbox

Steps to reproduce

https://elements.polymer-project.org/elements/paper-listbox?view=demo:demo/index.html&active=paper-listbox

@codekrolik
Copy link
Author

codekrolik commented Dec 21, 2016

This is an example of how hard and hacky it gets without the feature (Dart):

    //...userList was loaded from server via REST

    //clear listbox items
    PolymerDom listboxDom = Polymer.dom(userMultiChoice);
    for (Node childNode in listboxDom.childNodes)
      listboxDom.removeChild(childNode);

    //recreate listbox items
    List<int> selectedItems = new List<int>();
    for (int i = 0; i < userList.length; i++) {
      User user = userList[i];

      for (String username in selectedUsernames) {//~~~~
        if (username == user.username) {
          selectedItems.add(i);
          break;
        }
      }

      PaperItem item = new PaperItem();
      item.text = user.username;
      listboxDom.append(item);
    }

    //apply selection
    for (int item in selectedItems) {
      userMultiChoice.select(item);
    }

@fcFn
Copy link

fcFn commented Nov 22, 2017

You need to set the attribute on multi listbox like this <paper-listbox multi selected-values="[1, 2]">. This is described in the list of paper-listbox properties.

Also see #19.

@kylefarris
Copy link

This issue can probably be closed since @fcFn has clearly stated the answer...

@yglodt
Copy link

yglodt commented Feb 20, 2018

I have tried using paper-listbox multi selected-values="[1, 2]", and for it it only worked if the numbers are provided as String: ["1","2"]

Note that I use attr-for-selected="value" with <paper-item value="0">AAA</paper-item> etc

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants