diff --git a/ckan/public-bs2/base/javascript/modules/basic-form.js b/ckan/public-bs2/base/javascript/modules/basic-form.js index d1e97a4ce95..a3c57b094a1 100644 --- a/ckan/public-bs2/base/javascript/modules/basic-form.js +++ b/ckan/public-bs2/base/javascript/modules/basic-form.js @@ -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); } }; }); diff --git a/ckan/public/base/javascript/modules/basic-form.js b/ckan/public/base/javascript/modules/basic-form.js index d1e97a4ce95..a3c57b094a1 100644 --- a/ckan/public/base/javascript/modules/basic-form.js +++ b/ckan/public/base/javascript/modules/basic-form.js @@ -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); } }; });