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

Multiple form submissions with forms 13.0.1 and aspnet-validation #1182

Closed
james-whittington1 opened this issue Mar 5, 2024 · 1 comment
Closed
Labels
release/13.1.0 state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks type/feature

Comments

@james-whittington1
Copy link

A brief description of the issue goes here.

When using the aspnet-validation framework the form can be submitted multiple times.

I was sure that I remembered this being solved a long time ago, so I checked the js scripts and can see that the disabled state is only set when using jquery validation :(

Reproduction

Create a new project and set up and render a form to the front end.

Click the submit button several times. the form should keep resubmitting (i actually got some kind of server error relating to database scopes).

Confirm that the form was submitted more than once in the back office.

this can be fixed by including something like this in the aspnet-validation setup. Perhaps there is a way to have a shared routine to do handle this?

var submitInputs = document.querySelectorAll(".umbraco-forms-form input[type=submit]:not(.cancel)");
for (let i = 0; i < submitInputs.length; i++) {
var input = submitInputs[i] as HTMLInputElement;

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

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

 input.addEventListener("click", clickHandler);
@james-whittington1 james-whittington1 changed the title Multiple input submits Multiple form submissions with forms 13.0.4 and aspnet-validation Mar 5, 2024
@james-whittington1 james-whittington1 changed the title Multiple form submissions with forms 13.0.4 and aspnet-validation Multiple form submissions with forms 13.0.1 and aspnet-validation Mar 5, 2024
@AndyButland AndyButland added type/bug type/feature state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks release/13.1.0 and removed type/bug labels Mar 8, 2024
@AndyButland
Copy link

Thanks for reporting this @james-whittington1, and of course for providing the code snippet to help resolve. To be honest I hadn't realised we had this in place for the jquery validation, but given we do, we should certainly have it for the other validation framework supported. You'll find this in 13.1, due out next week.

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

No branches or pull requests

2 participants