Skip to content

Commit

Permalink
fix: restore form control validation in Safari (#6623)
Browse files Browse the repository at this point in the history
**Related Issue:** #6626

## Summary

This restores consistent usage of `requestSubmit` when submitting forms.
`submit` and `requestSubmit` [behave
differently](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit#usage_notes)
and it was currently not going through form validation in Safari. This
moves the polyfill to the form util to ensure it's available for
components using the form util.
  • Loading branch information
jcfranco committed Mar 21, 2023
1 parent 930c590 commit b293077
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/components/button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Build, Component, Element, h, Method, Prop, State, VNode, Watch } from "@stencil/core";
import "form-request-submit-polyfill/form-request-submit-polyfill";
import { closestElementCrossShadowBoundary } from "../../utils/dom";
import { FormOwner, resetForm, submitForm } from "../../utils/form";
import { InteractiveComponent, updateHostInteraction } from "../../utils/interactive";
Expand Down
3 changes: 2 additions & 1 deletion src/utils/form.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "form-request-submit-polyfill/form-request-submit-polyfill";
import { closestElementCrossShadowBoundary } from "./dom";
import { FunctionalComponent, h } from "@stencil/core";

Expand Down Expand Up @@ -144,7 +145,7 @@ export function submitForm(component: FormOwner): boolean {
return false;
}

"requestSubmit" in formEl ? formEl.requestSubmit() : (formEl as HTMLFormElement).submit();
formEl.requestSubmit();

return true;
}
Expand Down

0 comments on commit b293077

Please sign in to comment.