summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Monjoie <dmo@odoo.com>2016-04-26 11:16:37 +0200
committerDavid Monjoie <dmo@odoo.com>2016-04-26 11:21:20 +0200
commit6e3389ca73f2bbf97a9b706d8fc5d0af21f95006 (patch)
treeeca825586c222274d002e77d4fbff3ae9d0c4b16
parentda60ca91cc446c10eda5cbfc451cf5501f30a81d (diff)
[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.
-rw-r--r--addons/website_crm/views/website_crm.xml2
-rw-r--r--addons/website_form/static/src/js/website_form.js5
-rw-r--r--addons/website_hr_recruitment/views/templates.xml2
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 @@
</div>
<div class="form-group">
<div class="col-md-offset-3 col-sm-offset-4 col-sm-8 col-md-7">
- <button class="btn btn-primary btn-lg o_website_form_send">Send</button>
+ <span class="btn btn-primary btn-lg o_website_form_send">Send</span>
<span id="o_website_form_result"></span>
</div>
</div>
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 @@
</div>
<div class="form-group">
<div class="col-md-offset-3 col-sm-offset-4 col-sm-8 col-md-7">
- <button class="btn btn-primary btn-lg o_website_form_send">Submit</button>
+ <span class="btn btn-primary btn-lg o_website_form_send">Submit</span>
<span id="o_website_form_result"></span>
</div>
</div>