Skip to content

Setting on multiple select elements via classname does not work #12

Description

@netsensei

Hi! If you have multiple select elements on a page (e.g. a table with rows and each row has a select form element) you can't set the multiselect plugin on all elements using the class property.

For instance:

    <select class="foobar">
        <option value="bread">Bread</option>
        <option value="cereal">Cereal</option>
        <option value="pasta">Pasta</option>
        <option value="rice">Rice</option>
        <option value="meat">Meat</option>
        <option value="fish">Fish</option>
    </select>

    <select class="foobar">
        <option value="bread">Bread</option>
        <option value="cereal">Cereal</option>
        <option value="pasta">Pasta</option>
        <option value="rice">Rice</option>
        <option value="meat">Meat</option>
        <option value="fish">Fish</option>
    </select>

This bit will only initialize the multiselect on the first select element, not the second:

const foobar = new IconicMultiSelect({
    select: ".foobar",
});

foobar.init();

As a work around, you can do this:

  document.querySelectorAll("select").forEach(function (el) {
      const foobar = new IconicMultiSelect({
          select: "#" + el.id,
      });

      foobar.init();
  })

But this is convoluted, and it requires that every select element has an id property.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions