shoelace-style / shoelace

A collection of professionally designed, every day UI components built on Web standards. SHOELACE IS BECOMING WEB AWESOME 👇👇👇
https://webawesome.com
MIT License
12.64k stars 804 forks source link

Required Fields form validation #2139

Open karolskolasinski opened 1 month ago

karolskolasinski commented 1 month ago

Describe the bug

when sending a form with blank but required fields, an error message is shown for a random required field

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'shoelace official webpage'
  2. Click on Submit button
  3. See validation (error) message most often for the checkbox

Screenshots

image

image

Browser / OS

Additional information

should validate fields in the order they are in the form

claviska commented 1 month ago

Hi there. Unfortunately, this is a symptom of how we use the formdata event to make Shoelace form controls work with regular forms. I don't believe it's something we can easily fix in the current version (but if someone manages to, a PR would be welcome!).

That said, you'll be happy to know that Web Awesome ("Shoelace 3") has already moved to Form-associated Custom Elements via the ElementInternals API. This API didn't exist when Shoelace was first developed, but it lets us build form controls that act as first-class citizens in a native form.

I can confirm that this issue has already been solved in Web Awesome :)

karolskolasinski commented 2 weeks ago

what's more, if you create a form dynamically by adding inputs to it (e.g. you insert fields into the form using htmx), then validation of new fields does not work at all (it means submit behaves as if they were not there at all)