From 3ec98ae6b082c9eddcef2b9391bc7e764b6c6e4b Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 2 Jan 2018 14:16:44 +0100 Subject: [PATCH] [FIX] website_sale: can't send coupon code after an ajax request Before this commit, an user could only use the coupon form if he didn't perform any ajax request (eg: change quantity, already sent a code..). Since the cart html would be reinjected with theses ajax requests, the click event would not work afterward until the page got fully reload. Now, we changed the jquery click binding to work with dynamically injected DOM --- addons/website_sale/static/src/js/website_sale.js | 2 +- addons/website_sale_options/static/src/js/website_sale.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 88bbb95648c..d54978e290c 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -215,7 +215,7 @@ odoo.define('website_sale.website_sale', function (require) { return false; }); - $('.oe_website_sale .a-submit, #comment .a-submit').off('click').on('click', function (event) { + $('.oe_website_sale, #comment').off('click', '.a-submit').on('click', '.a-submit', function (event) { if (!event.isDefaultPrevented() && !$(this).is(".disabled")) { event.preventDefault(); $(this).closest('form').submit(); diff --git a/addons/website_sale_options/static/src/js/website_sale.js b/addons/website_sale_options/static/src/js/website_sale.js index b766a71200e..da7025d65bb 100644 --- a/addons/website_sale_options/static/src/js/website_sale.js +++ b/addons/website_sale_options/static/src/js/website_sale.js @@ -35,7 +35,7 @@ $('.oe_website_sale #add_to_cart, .oe_website_sale #products_grid .a-submit') $(this).remove(); }); - $modal.on('click', '.a-submit', function () { + $modal.on('click', '.a-submit', function (ev) { var $a = $(this); $form.ajaxSubmit({ url: '/shop/cart/update_option', @@ -50,6 +50,7 @@ $('.oe_website_sale #add_to_cart, .oe_website_sale #products_grid .a-submit') } }); $modal.modal('hide'); + ev.preventDefault(); }); $modal.on('click', '.css_attribute_color input', function (event) {