alpinejs-plugin-simple-validate
alpinejs-plugin-simple-validate copied to clipboard
Select type="multiple" validation fails with a disabled initial option
Hi, probably another edge case, hooray!
With a select set up like this:
<label for="test">Multi Select</label>
<select multiple name="test" id="test" required>
<option disabled="" selected="" value="">select at least one value</option>
<option value="1">option 1</option>
<option value="2" selected>option 2</option>
<option value="3" selected>option 3</option>
<option value="4">option 4</option>
<option value="5">option 5</option>
</select>
<div class="error-msg text-sm mt-2 text-red-600">
one option is required
</div>
</div>
validation will be triggered on submit. This is a slightly contrived example to replicate the effect of a form being returned to the user to edit some fields. Initial submit is fine, but that first <option disabled="" selected="" value="">select at least one value</option>
seems to confuse the parser.
Probably not a massive issue as we can work around it by removing that first disabled option, but it might be a useful thing to know for idiot-proofing the codebase.