Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Selected' option does not respect optgroups #30

Closed
coneybeare opened this issue Dec 24, 2012 · 2 comments
Closed

'Selected' option does not respect optgroups #30

coneybeare opened this issue Dec 24, 2012 · 2 comments

Comments

@coneybeare
Copy link

Scenario:

<select class="selectpicker">
<option>I need help with...</option>
<optgroup label="Group 1">
    <option value=3319  >1</option>
    <option value=3325  >2</option>
    <option value=3430  >3</option>
</optgroup>
<optgroup label="Group 2">
    <option value=3431  >4</option>
    <option value=3432  >5</option>
    <option value=3433  >6</option>
    <option value=3434  >7</option>
</optgroup>
<option value=3435  >8</option>
<option value=3436  >9</option>
<option value=3437  >10</option>
<option value=3438  >11</option>
<option value=3439 selected='selected' >12</option>
<option value=3440  >13</option>
<option value=3441  >14</option>
</select>

This will cause item 7 to be displayed instead of the correct 12. Here is why I think it is happening.

The code must be iterating over the select tag to find the index of the selected option. If it sees an optgroup, it does not expand it, but counts it as 1. In the above example, it optgroup is not expanded, the selected item is the 8th item on this list.

When deciding which index to put the selected on after rendering, optgroup is included so the 8th element is chosen, in this case: 7.

@caseyjhol
Copy link
Member

Are you using the newest version? I believe this was fixed in commit a31e97b.

@coneybeare
Copy link
Author

Yup, updating fixed it, thanks.

    Matt Coneybeare

App Maker | Rock Star | Human Being

On Dec 27, 2012, at 3:18 PM, caseyjhol notifications@github.com wrote:

Are you using the newest version? I believe this was fixed in commit a31e97b.


Reply to this email directly or view it on GitHub.

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

No branches or pull requests

2 participants