-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #40. #82
Fix issue #40. #82
Conversation
Listen for submit events on the closest submit button and if the form is invalid prevent the default handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Thanks!
const internals = internalsMap.get(node); | ||
return internals.reportValidity(); | ||
}); | ||
form.addEventListener('click', event => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice and it does work for most use cases. But forms can be submitted with other events (like typing "Enter" in a field). So, we need to also keep in mind those use cases. Do you think opening an issue about this is worth it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx, for the annotation. However, according to the spec, hitting enter in a field causes "the user agent to fire a click event at that default button."
EDIT:
If it is wanted to force this behavior on custom elements, then a new issue is certainly worth it.
There is an ongoing discussion regarding faCE and implicit submission WICG Issue 815. I would wait for a decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While pressing enter in an input field, this doesn't necessarily hold true for FACE elements, FWIW. I think this is fine as is. If you do happen upon any use cases, open an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This does works nicely!
Listen for submit events on the closest submit button and if the form is invalid prevent the default handling.
For more information see this explanation.