Skip to content
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 auto submit on non-form elements #1190

Merged
merged 4 commits into from
Nov 9, 2023
Merged

Fix auto submit on non-form elements #1190

merged 4 commits into from
Nov 9, 2023

Conversation

thet
Copy link
Member

@thet thet commented Nov 9, 2023

There are cases where pat-autosubmit is defined on non-form elements, like:

<form>
  <div class="pat-autosubmit">
    <input>
  </div>
</form>

pat-autosubmit invoked a submit event but that never reached the form because that follows not the standard and submit events are meant to be invoked on form elements (or maybe inputs, which did work although I can't derive that behavior from the specs).
See:
https://developer.mozilla.org/en-US/docs/Web/API/SubmitEvent
https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#submitevent

This use case was broken since Patternslib 9.9.7 where we switched to JavaScript submit events from jQuery submit events to fix another problem.

Now the submit event is always invoked on the related form element. Actually the input element where a change happens can be outside the form itself if it is connected with the form via the form attribute.

thet added 4 commits November 10, 2023 00:17
Add a function to find a related form element. If called on any element
it would first try to get a input element and get it's associated form -
which can be different and as a last resort to find the element's
enclosing form. Otherwise return undefined.
Fix a problem introduces in Patternslib 9.9.7 where pat-autosubmit did
not work when not defined on a form or input element.

As a side effect, the submit event is now always invoked on the related
or nearest form of the element where pat-autosubmit was defined on. If
that element is not a form element a related (input.form) or the nearest
parent form is searched and the submit event invoked upon.
@thet thet merged commit a51baeb into master Nov 9, 2023
@thet thet deleted the fix-autosubmit branch November 9, 2023 23:25
@thet
Copy link
Member Author

thet commented Nov 9, 2023

/cc @cornae

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant