The placeholder item is not visible when used together with optgroup. (Tested with version 3.0.2)
This isn't working (Select Value is not visible in the dropdown)
<select>
<option value placeholder>Select Value</option>
<optgroup label="Group 1">
<option value="1">One</option>
<option value="2">Two</option>
</optgroup>
<optgroup label="Group 2">
<option value="3">Three</option>
<option value="4">Four</option>
</optgroup>
</select>
Hey - looks like this is more just an issue of having a combination of standalone options alongside option groups. Looks like standalone options are ignored when the Choices detects groups.
Let me investigate.
Line 2658:
const passedGroups = Array.from(this.passedElement.getElementsByTagName('OPTGROUP'));
if (passedGroups && passedGroups.length) {
passedGroups.forEach((group) => {
this._addGroup(group, (group.id || null));
});
} else {
...
}
Having the same issue right now. The jsfiddle given above isn't working, even if I replace JS source with choices.js v3.0.3. Any idea? Thanks.
@jshjohnson Any word on this? I'm trying to do the same thing, with a placeholder value that isn't appearing ahead of <optgroup>
+1
@jshjohnson any updates on the state of this bug?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi :)
I am having this bug right now, i use optgroup and when i use a place holder in the select or directly in the configuration, it disappear instantly !
I've created a fiddle to reproduce the behavior https://jsfiddle.net/maocdg15/2/
also, i can't add a placeholder attribute in the option tag ... that's why I've opened this issue.
Thanks !
Most helpful comment
Hey - looks like this is more just an issue of having a combination of standalone options alongside option groups. Looks like standalone options are ignored when the Choices detects groups.
Let me investigate.