Skip to content

Form controls: why type="module" required for validation and preventDefault #782

Answered by claviska
trailsnail asked this question in Help
Discussion options

You must be logged in to vote

Scripts with type="module" are deferred, whereas scripts without it are executed synchronously. Until ElementInternals lands, Shoelace needs to use a reactive controller to handle form submissions.

this.form.addEventListener('formdata', this.handleFormData);
this.form.addEventListener('submit', this.handleFormSubmit);

Unfortunately, that means it's possible to attach listeners that execute before the controller's listeners. It's something we need to workaround until we can use ElementInternals to make Shoelace form controls first-class citizens.

You might recall in previous versions there was an <sl-form> eleme…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@trailsnail
Comment options

Answer selected by trailsnail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants