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

Prevent from submitting the ajax form twice #6617

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from

Conversation

qzminski
Copy link
Member

It may happen that the form processing takes a while, and it may happen that the visitor will not notice that and submit the form again. This could result in a double form submission. This improvement should solve that.

One open question is: should we disable the form fields right after submission, for the better UX?

/cc @Toflar

@fritzmg
Copy link
Contributor

fritzmg commented Dec 11, 2023

imho this is relevant for forms in general, not just when $this->ajax is enabled.

<form onsubmit="this.inert=true">

@Toflar
Copy link
Member

Toflar commented Dec 11, 2023

One open question is: should we disable the form fields right after submission, for the better UX?

Imho yes, wdyt @contao/developers? Not even sure if there's a simple variant in 2023 but at least the submit button should probably be disabled.

@fritzmg
Copy link
Contributor

fritzmg commented Dec 11, 2023

What about adding the aforementioned onsubmit attribute by default? inert seems to be pretty new and I have no real experience with it whatsoever - or whether this is even good practise or not. But I did some quick tests and it works as intended both for regular and AJAX forms.

@aschempp
Copy link
Member

I don't think inert is the correct use. It will for example remove the element from the accessibility-tree.
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inert

Not sure if there's a better standard, but adding any data attribute would allow to apply CSS for styling a disabled submit button as well as disabling mouse events.

@ausi
Copy link
Member

ausi commented Dec 13, 2023

We already discussed this in #1933 (comment)

If we want to change course here, I’d use a script similar to the one metioned in whatwg/html#5312

@leofeyer leofeyer added the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature up for discussion Issues and PRs which will be discussed in our monthly Mumble calls.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants