[FIX] website_form: prevent double clicking send
Behavior prior to the commit:
A user can double click the "Send" button when submitting a form on the
website. Because the event handler is removed on the first click, the
second submission uses the browser default behavior and posts the form
to an incorrect URL, resulting in a 404 error for the user.
Behavior after the commit:
The button is disabled after the first click.
Note:
Using `.attr('disabled')` is sufficient both to disable the button and
to give the disabled visual on all browsers since IE9, but we keep
`.addClass('disabled')` and `.off()` for cases where the clickable is not a
`button` but a link.
opw-2356402
closes odoo/odoo#61111
X-original-commit: 0eed92da709dba843a7f2f82aee772313e3d4630
Signed-off-by: Nicolas Galler <nicocrm@users.noreply.github.com>
This commit is contained in:
@@ -98,7 +98,9 @@ odoo.define('website_form.s_website_form', function (require) {
|
||||
send: async function (e) {
|
||||
e.preventDefault(); // Prevent the default submit behavior
|
||||
// Prevent users from crazy clicking
|
||||
this.$target.find('.s_website_form_send, .o_website_form_send').addClass('disabled'); // !compatibility
|
||||
this.$target.find('.s_website_form_send, .o_website_form_send')
|
||||
.addClass('disabled') // !compatibility
|
||||
.attr('disabled', 'disabled');
|
||||
|
||||
var self = this;
|
||||
|
||||
@@ -164,7 +166,9 @@ odoo.define('website_form.s_website_form', function (require) {
|
||||
ajax.post(this.$target.attr('action') + (this.$target.data('force_action') || this.$target.data('model_name')), form_values)
|
||||
.then(function (result_data) {
|
||||
// Restore send button behavior
|
||||
self.$target.find('.s_website_form_send, .o_website_form_send').removeClass('disabled'); // !compatibility
|
||||
self.$target.find('.s_website_form_send, .o_website_form_send')
|
||||
.removeAttr('disabled')
|
||||
.removeClass('disabled'); // !compatibility
|
||||
result_data = JSON.parse(result_data);
|
||||
if (!result_data.id) {
|
||||
// Failure, the server didn't return the created record ID
|
||||
@@ -295,7 +299,9 @@ odoo.define('website_form.s_website_form', function (require) {
|
||||
|
||||
update_status: function (status, message) {
|
||||
if (status !== 'success') { // Restore send button behavior if result is an error
|
||||
this.$target.find('.s_website_form_send, .o_website_form_send').removeClass('disabled'); // !compatibility
|
||||
this.$target.find('.s_website_form_send, .o_website_form_send')
|
||||
.removeAttr('disabled')
|
||||
.removeClass('disabled'); // !compatibility
|
||||
}
|
||||
var $result = this.$('#s_website_form_result, #o_website_form_result'); // !compatibility
|
||||
|
||||
|
||||
Reference in New Issue
Block a user