From 6e3389ca73f2bbf97a9b706d8fc5d0af21f95006 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Tue, 26 Apr 2016 11:16:37 +0200 Subject: [PATCH] [FIX] website_form: prevent users from crazy clicking If the feedback of a form is too slow, people might be tempted to click a second time, trigerring a second request. If, after that, the result has not been received yet, the user might be tempted to click a lot of time because he is angry at such slowness. This behavior would trigger a record creation each time the user clicked the submit button. This fix disables the button once it has been clicked once, and re-enable it if the record could not be created, which means that there was an error in the input and the user needs to change the values and try again. The button has been changed to a span to avoid the default browser behavior to post the form when no function is bound on the send button. --- addons/website_crm/views/website_crm.xml | 2 +- addons/website_form/static/src/js/website_form.js | 5 +++++ addons/website_hr_recruitment/views/templates.xml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/website_crm/views/website_crm.xml b/addons/website_crm/views/website_crm.xml index db2086b07a1..fc4208a1e7e 100644 --- a/addons/website_crm/views/website_crm.xml +++ b/addons/website_crm/views/website_crm.xml @@ -44,7 +44,7 @@
- + Send
diff --git a/addons/website_form/static/src/js/website_form.js b/addons/website_form/static/src/js/website_form.js index cea891ef135..ad5dcaa5cb7 100644 --- a/addons/website_form/static/src/js/website_form.js +++ b/addons/website_form/static/src/js/website_form.js @@ -47,6 +47,7 @@ odoo.define('website_form.animation', function (require) { send: function(e) { e.preventDefault(); // Prevent the default submit behavior + this.$target.find('.o_website_form_send').off(); // Prevent users from crazy clicking var self = this; @@ -211,6 +212,10 @@ odoo.define('website_form.animation', function (require) { }, update_status: function(status) { + var self = this; + if (status != 'success') { // Restore send button behavior if result is an error + this.$target.find('.o_website_form_send').on('click',function(e) {self.send(e);}); + } this.$target.find('#o_website_form_result').replaceWith(qweb.render("website_form.status_" + status)) }, }); diff --git a/addons/website_hr_recruitment/views/templates.xml b/addons/website_hr_recruitment/views/templates.xml index 3ac6736a7e2..38643a7479e 100644 --- a/addons/website_hr_recruitment/views/templates.xml +++ b/addons/website_hr_recruitment/views/templates.xml @@ -195,7 +195,7 @@
- + Submit