From 708f15c9b11faafa024d51ce98485e2d9435ff58 Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Thu, 1 Jun 2023 14:30:03 +0000 Subject: [PATCH] [FIX] web: don't use the compileButton fn for bootstrap toggles Steps to reproduce ================== - Use a mobile (xs) viewport - Go to sign - Click on "Action" -> InvalidButtonParamsError Cause of the issue ================== The bootstrap button should not be compiled as an action button Solution ======== Don't call compileButton for button with the data-bs-toggle attribute We also need to cancel the global click to let bootstrap handle the action opw-3278906 closes odoo/odoo#123579 X-original-commit: 5f569eedf9ed4e19b1fab1c83f7d315684097a7f Related: odoo/enterprise#41906 Signed-off-by: Julien Mougenot (jum) --- .../static/src/views/kanban/kanban_record.js | 2 +- addons/web/static/src/views/view_compiler.js | 4 +- .../views/kanban/kanban_compiler_tests.js | 56 +++++++++++++++++++ .../views/{ => kanban}/kanban_view_tests.js | 0 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 addons/web/static/tests/views/kanban/kanban_compiler_tests.js rename addons/web/static/tests/views/{ => kanban}/kanban_view_tests.js (100%) diff --git a/addons/web/static/src/views/kanban/kanban_record.js b/addons/web/static/src/views/kanban/kanban_record.js index dc87c9e1643..0f2188dc862 100644 --- a/addons/web/static/src/views/kanban/kanban_record.js +++ b/addons/web/static/src/views/kanban/kanban_record.js @@ -30,7 +30,7 @@ const { COLORS } = ColorList; const formatters = registry.category("formatters"); // These classes determine whether a click on a record should open it. -export const CANCEL_GLOBAL_CLICK = ["a", ".dropdown", ".oe_kanban_action"].join(","); +export const CANCEL_GLOBAL_CLICK = ["a", ".dropdown", ".oe_kanban_action", "[data-bs-toggle]"].join(","); const ALLOW_GLOBAL_CLICK = [".oe_kanban_global_click", ".oe_kanban_global_click_edit"].join(","); /** diff --git a/addons/web/static/src/views/view_compiler.js b/addons/web/static/src/views/view_compiler.js index 40891a0addb..53ae5d0b96a 100644 --- a/addons/web/static/src/views/view_compiler.js +++ b/addons/web/static/src/views/view_compiler.js @@ -199,8 +199,8 @@ export class ViewCompiler { this.id = 1; /** @type {Compiler[]} */ this.compilers = [ - { selector: "a[type],a[data-type]", fn: this.compileButton }, - { selector: "button", fn: this.compileButton, doNotCopyAttributes: true }, + { selector: "a[type]:not([data-bs-toggle]),a[data-type]:not([data-bs-toggle])", fn: this.compileButton }, + { selector: "button:not([data-bs-toggle])", fn: this.compileButton, doNotCopyAttributes: true }, { selector: "field", fn: this.compileField }, { selector: "widget", fn: this.compileWidget }, ]; diff --git a/addons/web/static/tests/views/kanban/kanban_compiler_tests.js b/addons/web/static/tests/views/kanban/kanban_compiler_tests.js new file mode 100644 index 00000000000..48651307a67 --- /dev/null +++ b/addons/web/static/tests/views/kanban/kanban_compiler_tests.js @@ -0,0 +1,56 @@ +/** @odoo-module **/ +import { KanbanCompiler } from "@web/views/kanban/kanban_compiler"; +import { registry } from "@web/core/registry"; +import { makeFakeLocalizationService } from "@web/../tests/helpers/mock_services"; + +function compileTemplate(arch) { + const parser = new DOMParser(); + const xml = parser.parseFromString(arch, "text/xml"); + const compiler = new KanbanCompiler({ kanban: xml.documentElement }); + return compiler.compile("kanban").outerHTML; +} + +function assertTemplatesEqual(template1, template2) { + if (template1.replace(/\s/g, "") === template2.replace(/\s/g, "")) { + QUnit.assert.ok(true); + } else { + QUnit.assert.strictEqual(template1, template2); + } +} + +QUnit.module("Kanban Compiler", (hooks) => { + hooks.beforeEach(() => { + // compiler generates a piece of template for the translate alert in multilang + registry.category("services").add("localization", makeFakeLocalizationService()); + }); + + QUnit.test("bootstrap dropdowns with kanban_ignore_dropdown class should be left as is", async () => { + const arch = ` + + +
+ + +
+
+
+
`; + const expected = ` + + + +
+ + +
+
+
+
+
`; + assertTemplatesEqual(compileTemplate(arch), expected); + }); +}); diff --git a/addons/web/static/tests/views/kanban_view_tests.js b/addons/web/static/tests/views/kanban/kanban_view_tests.js similarity index 100% rename from addons/web/static/tests/views/kanban_view_tests.js rename to addons/web/static/tests/views/kanban/kanban_view_tests.js