Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
e523ff5a
Verified
Commit
e523ff5a
authored
2 years ago
by
Drew Webber
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1705618
: new js file missing from previous commit
parent
353a22fc
No related branches found
No related tags found
1 merge request
!7330
Issue #3306390 by poker10, catch, Fabianx, pwolanin, rvtraveller: [D7]...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
misc/form-single-submit.js
+60
-0
60 additions, 0 deletions
misc/form-single-submit.js
with
60 additions
and
0 deletions
misc/form-single-submit.js
0 → 100644
+
60
−
0
View file @
e523ff5a
(
function
(
$
)
{
/**
* Prevents consecutive form submissions of identical form values.
*
* Repetitive form submissions that would submit the identical form values are
* prevented, unless the form values are different from the previously
* submitted values.
*
* This is a simplified re-implementation of a user-agent behavior that should
* be natively supported by major web browsers, but at this time, only Firefox
* has a built-in protection.
*
* A form value-based approach ensures that the constraint is triggered for
* consecutive, identical form submissions only. Compared to that, a form
* button-based approach would (1) rely on [visible] buttons to exist where
* technically not required and (2) require more complex state management if
* there are multiple buttons in a form.
*
* This implementation is based on form-level submit events only and relies on
* jQuery's serialize() method to determine submitted form values. As such, the
* following limitations exist:
*
* - Event handlers on form buttons that preventDefault() do not receive a
* double-submit protection. That is deemed to be fine, since such button
* events typically trigger reversible client-side or server-side operations
* that are local to the context of a form only.
* - Changed values in advanced form controls, such as file inputs, are not part
* of the form values being compared between consecutive form submits (due to
* limitations of jQuery.serialize()). That is deemed to be acceptable,
* because if the user forgot to attach a file, then the size of HTTP payload
* will most likely be small enough to be fully passed to the server endpoint
* within (milli)seconds. If a user mistakenly attached a wrong file and is
* technically versed enough to cancel the form submission (and HTTP payload)
* in order to attach a different file, then that edge-case is not supported
* here.
*
* Lastly, all forms submitted via HTTP GET are idempotent by definition of HTTP
* standards, so excluded in this implementation.
*/
Drupal
.
behaviors
.
formSingleSubmit
=
{
attach
:
function
()
{
function
onFormSubmit
(
e
)
{
var
$form
=
$
(
e
.
currentTarget
);
var
formValues
=
$form
.
serialize
();
var
previousValues
=
$form
.
attr
(
'
data-drupal-form-submit-last
'
);
if
(
previousValues
===
formValues
)
{
e
.
preventDefault
();
}
else
{
$form
.
attr
(
'
data-drupal-form-submit-last
'
,
formValues
);
}
}
$
(
'
body
'
).
once
(
'
form-single-submit
'
)
.
delegate
(
'
form:not([method~="GET"])
'
,
'
submit.singleSubmit
'
,
onFormSubmit
);
}
};
})(
jQuery
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment