colinaut / alpinejs-plugin-simple-validate

Simple Alpine form validation plugin
96 stars 4 forks source link

Select type="multiple" validation fails with a disabled initial option #29

Open Rocketpilot opened 1 month ago

Rocketpilot commented 1 month ago

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.

colinaut commented 1 month ago

I'll look into this. I've got a bunch on my plate work wise at the moment so I can't promise a speedy response.

Rocketpilot commented 1 month ago

Definitely not a show-stopper, and hope your workload eases off!