jQuery-Selectric icon indicating copy to clipboard operation
jQuery-Selectric copied to clipboard

Incorrect result when optGroup with multiple

Open ruoqianfengshao opened this issue 7 years ago • 2 comments

an error value get when init a multiple select with optGroup. I add following code in public/index.html

      <div class="item">
          <select multiple>
            <option>Select with optgroup and multiple</option>
            <optgroup label="Group 1">
              <option>Option 1.1</option>
            </optgroup>
            <optgroup label="Group 2">
              <option selected>Option 2.1</option>
              <option selected>Option 2.2</option>
            </optgroup>
            <optgroup label="Group 3" disabled>
              <option>Option 3.1</option>
              <option>Option 3.2</option>
              <option>Option 3.3</option>
            </optgroup>
          </select>
        </div>

And get an error value after init, like this image image

Is this an expected performance? Thank u for viewing this issue!

ruoqianfengshao avatar Dec 01 '17 08:12 ruoqianfengshao

The way to calculate index of option which seleted may be not fit for this place.

    if ( $selected.length > 1 && _this.state.multiple ) {
        selectedIndex = [];
        $selected.each(function() {
          selectedIndex.push($(this).index());
        });
      }

I modified it :

    if ( $selected.length > 1 && _this.state.multiple ) {
        selectedIndex = [];
        $selected.each(function() {
          selectedIndex.push($(_this.$element.find("option")).index(this));
        });
      }

Wish u can see this and give me a reply, thank u.

ruoqianfengshao avatar Dec 01 '17 08:12 ruoqianfengshao

Hey, I just created a pull-request based on your work.

It works like a charm here. Hope the maintainer will merge it soon.

In case you want to use this fork in one project via npm : npm install --save github:Jjoye/jQuery-Selectric

Congrats 💪

2j0ye avatar Feb 02 '18 15:02 2j0ye