The core/drupal.form library is not added to all drupal forms.
- Add
core/drupal.form library to all Drupal forms.
- Create a new library in the user module and a new user.register.js file where the code of
Drupal.behaviors.fillUserInfoFromBrowser will be moved and add this new user library to the registration form.
Original report
There is a problem with form submission if you quickly double click the form.
Steps to reproduce:
1. Download and install the Drupal core
2. Go to /admin/structure/types/manage/article/fields/add-field
3. Select any type of field (lets pick Boolean)
4. Type the title "Test"
5. Double click the "Save and Continue"
Result:
It will be presented with "The machine-readable name is already in use. It must be unique."
The field of "field_test" was created successfully but unable to continue the process because of the double posting to the server, it causes the whole thing break.
Comments
Comment #1
rajeev h commentedWhen user clicks on The submit button the button will be hidden with, please wait.. message
Comment #2
FreekyMage commentedI'm not sure this is the way to do this, but here is some general code feedback on the ticket:
Drupal.t('Please wait...')$('#field-ui-field-storage-add-form #edit-submit')can be replaced with$(this)Comment #3
nod_This is supposed to be fixed by #1705618: Double click prevention on form submission. Which browser and version are you using?
I'd rather avoid going down the path #1 is going. We really don't want to be handling form state if we can avoid it.
Can someone check on firefox whether the same bug appears or not?
Comment #4
nod_Comment #5
FreekyMage commentedTested in Firefox, no problem there. IE (11) has the problem, just like Chrome (39).
Comment #6
yesct commentedThank you for working on this issue.
We should all try and use the same sprint tag. According to https://groups.drupal.org/node/447258 it should be SprintWeekend2015 with no #.
Comment #7
rajeev h commentedWhen user clicks on The submit button the button will be hidden with replacing text as- please wait..
Comment #8
alimac commented@rajeev.rymec Thanks for posting the patch. We should all try and use the same sprint tag. According to https://groups.drupal.org/node/447258 it should be SprintWeekend2015 with no #.
Comment #9
yesct commented@rajeev.rymec Thank you for trying to help with this issue.
We work against dev versions, not tagged milestones like betas.
If the code base has changed since beta 4, you may have to reroll the patch. But this applies fine to head.
Actually... the patch in #1 still applies to head. Why upload a new patch that is exactly the same?
Why change this from a bug to a task?
See https://www.drupal.org/core/issue-category for definition of issue category values: Bug, Task, Feature request, Support request.
Comment #10
rajeev h commented@all Thanks for your suggestions, there is some change in patch 2
Comment #11
nod_Thanks for the patch but what we need is to look into why
Drupal.behaviors.formSingleSubmitis not doing it's job when there is a double click, not adding more code.This piece of code was supposed to replicate Firefox behavior of not submitting a form several times if the form values haven't changed. See https://github.com/sun/jquery-form-submit-single for more detailed explanations of what we're going for and please read especially the pharagraph called On not manipulating the user interface.
The patch submitted is suited for a on-off project, it is not suited for Drupal core. It is to specific and makes many assumptions Drupal core can't afford to make.
Comment #12
nod_Just checked, form.js is not added to the page, that is the problem.
What needs to be done is to move
Drupal.behaviors.fillUserInfoFromBrowserout of form.js and in a new js file in the user module (called user.register.js or something) and add it to the registration form. Then make surecore/drupal.formlibrary is added to all drupal forms so that we have the Drupal event for updated values as well as double submit protection.Comment #13
k4v commentedComment #14
k4v commentedThis is a first try, not sure if I got the right spot to add drupal.form globally.
Comment #15
k4v commentedComment #17
k4v commentedMinor changes nitpicked by @tstoeckler =)
Comment #18
wim leersUGH. -1
This will cause JS to be loaded on pretty much every page, because e.g. the search form is going to be on almost every page. Isn't there any other way?
First thought: only do this if we know it's going to submit actual data. E.g.
SearchBlockFormsets$form['#method'] = 'get';. And it doesn't set any#submithandler. In other words: find a clever enough heuristic to only then add this form.Second thought: can we avoid doing this for anonymous users?
Third thought: cookie with the form ID + form build ID that's just been submitted, so we can detect it on a resubmit?
Comment #19
tstoecklerInteresting thoughts. Let's send this to the testbot in the meantime.
Comment #21
k4v commentedComment #32
quietone commentedI tested this on Drupal 9.4.x, standard install. I used the steps to reproduce in the Issue Summary and was not able to reproduce the problem.
If you are experiencing this problem on a supported version of Drupal, re-open and provide complete steps to reproduce,
Thanks.