Choices
Choices copied to clipboard
Options remain disabled after enabling a select
Describe the bug If a select has the disabled attribute set in the original HTML code before Choices is created all options remain disabled after a call to .enable();
To Reproduce See attached example html file.
Expected behavior Both example selects are disabled after loading the file. After a click on "enable" the options of the first select remain disabled, the options of the second select are enable correct.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/public/assets/styles/base.min.css"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/public/assets/styles/choices.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/public/assets/scripts/choices.min.js"></script>
</head>
<body>
<div class="container">
<div class="section">
<label>Buggy init on disabled select</label>
<select name="test1" id="test1" disabled>
<option value="1">Option A</option>
<option value="2" disabled>Option B</option>
<option value="3">Option C</option>
</select>
<label>Workaround init on disabled select</label>
<select name="test2" id="test2" disabled>
<option value="1">Option A</option>
<option value="2" disabled>Option B</option>
<option value="3">Option C</option>
</select>
<button type="button" onclick="enableBoth()">Enable</button>
<button type="button" onclick="disableBoth()">Disable</button>
</div>
</div>
<script type="text/javascript">
let choices1, choices2;
function enableBoth() {
choices1.enable();
choices2.enable();
}
function disableBoth() {
choices1.disable();
choices2.disable();
}
(function() {
const test1Select = document.getElementById('test1');
choices1 = new Choices(test1Select);
const test2Select = document.getElementById('test2');
test2Select.disabled = false;
choices2 = new Choices(test2Select);
choices2.disable();
})();
</script>
</body>
</html>
Hi guys. Any chance that the bug will be fixed and a new release will be created? The fix of @codeflow-biz seems to be really simple. Thanks!
hi, still no release for this fix ?
Hi. You can use my fork until the fix is in the main repo. I committed the fully build, ready to use files as well. My build is based on the currently latest release just with 2 or 3 fixes.