-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Prevent Double Submit #206
Comments
Can you describe in more detail what you mean by "double-form submits"? |
The user double-clicks the 'submit' button. The second click should be ignored while the first submit is being processed, until the submit either returns an error or success. Best, |
You can disable the submit button while You can "watch" the form state in our playground: https://modularforms.dev/qwik/playground/login |
I did think of that but it does not prevent from the form being submitted multiple times by pressing 'enter'. It would be good to have a 'pending' form signal, or maybe adding a 'pending' property to form.response.status |
Are you sure about that? |
Yes, if you have the focus on an input and press enter, it will submit the form. I've added an external signal to solve the issue. UPDATE: As you hinted, pressing enter twice in the input field does not submit the form twice and treats the action the same as a 'double click' on an <input tag set to 'submit' instead of 'button'. In my case, I had an 'onkeypress' event detecting 'enter' on a textarea to submit the form which could potentially cause a double-submit but is a unique issue to how I implemented the form. I fixed it and modular forms works as expected. |
I would expect that adding |
I think disabling the <button type="submit" prevents double-submits for double-clicks on the button and double-enter in an input field. I suspect adding an onKeypress handler detecting the 'enter' keypress on a textarea input and having that handler call 'myform.submit' in JS would still cause a double-submit. As you suggest, adding if (!formState.submitting) myForm.submit in the onKeypress event is the right solution in that case. All good now, thanks. |
What is the 'ModularForms' way of preventing double-form submits?
Thank you,
The text was updated successfully, but these errors were encountered: