Skip to content

Commit

Permalink
[#3773] Prevent multiple consecutive form submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandar Jovanov committed Aug 22, 2017
1 parent 3fa8d9b commit 37b2e24
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ckan/public-bs2/base/javascript/modules/basic-form.js
Expand Up @@ -2,7 +2,23 @@ this.ckan.module('basic-form', function (jQuery) {
return {
initialize: function () {
var message = this._('There are unsaved modifications to this form');

$.proxyAll(this, /_on/);

this.el.incompleteFormWarning(message);

// Disable the submit button on form submit, to prevent multiple
// consecutive form submissions.
this.el.on('submit', this._onSubmit);
},
_onSubmit() {

// The button is not disabled immediately so that its value can be sent
// the first time the form is submitted, because the "save" field is
// used in the backend.
setTimeout(function() {
this.el.find('button[name="save"]').attr('disabled', true);
}.bind(this), 0);
}
};
});
16 changes: 16 additions & 0 deletions ckan/public/base/javascript/modules/basic-form.js
Expand Up @@ -2,7 +2,23 @@ this.ckan.module('basic-form', function (jQuery) {
return {
initialize: function () {
var message = this._('There are unsaved modifications to this form');

$.proxyAll(this, /_on/);

this.el.incompleteFormWarning(message);

// Disable the submit button on form submit, to prevent multiple
// consecutive form submissions.
this.el.on('submit', this._onSubmit);
},
_onSubmit() {

// The button is not disabled immediately so that its value can be sent
// the first time the form is submitted, because the "save" field is
// used in the backend.
setTimeout(function() {
this.el.find('button[name="save"]').attr('disabled', true);
}.bind(this), 0);
}
};
});

0 comments on commit 37b2e24

Please sign in to comment.