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

Update to form validation in #1182 has removed form submit event #1199

Closed
kieron-mcintyre opened this issue Apr 2, 2024 · 3 comments
Closed
Labels
release/13.1.2 state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks type/bug

Comments

@kieron-mcintyre
Copy link

kieron-mcintyre commented Apr 2, 2024

The update in #1182 has resulted in a form's submit event not being raised when submitted.

The following code has been implemented and will trigger the form to be submitted but it will not raise a submit event:

form.submit();

This is an issue because there will be sites which rely on the the submit event for form and field manipulation, tracking etc.

Solution

Using form.requestSubmit() instead of form.submit() in following code will do the same and raise the form's submit event:

 const clickHandler = (e: Event) => {
	 e.preventDefault();
	 const form = input.closest('form') as HTMLFormElement;

	 validationService.validateForm(form, (valid) => {
		 if (valid) { 
			 form.requestSubmit(input);
			 input.setAttribute("disabled", "disabled");  
		 }
	 }); 
 }

input.addEventListener("click", clickHandler);

The details of this are found here:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit and
https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit#usage_notes

Browser Support

Given that form.requestSubmit() is not supported by older browsers (https://caniuse.com/?search=requestSubmit), it might be worth considering implementing a polyfill, e.g. https://github.com/javan/form-request-submit-polyfill.

@kieron-mcintyre kieron-mcintyre changed the title Update #1182 to form validation has removed form submit event Update to form validation in #1182 has removed form submit event Apr 2, 2024
@AndyButland AndyButland added type/bug state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks release/13.1.2 labels Apr 3, 2024
@AndyButland
Copy link

Thanks for the report @kieron-mcintyre along of course with the suggested resolution and additional detail. We'll apply this from the next patch to restore the previous behaviour.

Rather than polyfill - given this looks to be fairly widely supported - I was minded to use the check for availability and fallback suggested here.

@kieron-mcintyre
Copy link
Author

@AndyButland Thanks for incorporating this. Is there a date expected for the release of this fix, please?

@AndyButland
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release/13.1.2 state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks type/bug
Projects
None yet
Development

No branches or pull requests

2 participants