From 8a6f045a74bf64291d3dc9238f3922b071c78a34 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 20 Sep 2022 07:44:10 +0000 Subject: [PATCH] [FIX] web: form: keep data-hotkey attribute on buttons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, the data-hotkey attribute set on button nodes in form views was ignored. This commit re-introduces the feature, enabling the keynav on those buttons. closes odoo/odoo#100563 Signed-off-by: Georis François (fge) --- .../src/views/view_button/view_button.js | 1 + .../src/views/view_button/view_button.xml | 1 + addons/web/static/src/views/view_compiler.js | 3 ++ .../tests/views/form/form_view_tests.js | 29 +++++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/addons/web/static/src/views/view_button/view_button.js b/addons/web/static/src/views/view_button/view_button.js index e2573a0439c..afbd9b4cee6 100644 --- a/addons/web/static/src/views/view_button/view_button.js +++ b/addons/web/static/src/views/view_button/view_button.js @@ -130,6 +130,7 @@ ViewButton.props = [ "className?", "context?", "clickParams?", + "hotkey?", "icon?", "defaultRank?", "disabled?", diff --git a/addons/web/static/src/views/view_button/view_button.xml b/addons/web/static/src/views/view_button/view_button.xml index db84af78392..029cc22d641 100644 --- a/addons/web/static/src/views/view_button/view_button.xml +++ b/addons/web/static/src/views/view_button/view_button.xml @@ -11,6 +11,7 @@ t-att-href="props.tag === 'a' and '#'" t-att-style="props.style" t-att-type="clickParams.type" + t-att-data-hotkey="props.hotkey" t-att-data-tooltip-template="hasBigTooltip ? 'views.ViewButtonTooltip' : false" t-att-data-tooltip-info="hasBigTooltip ? tooltip : false" t-att-data-tooltip="hasSmallToolTip ? props.title : false" diff --git a/addons/web/static/src/views/view_compiler.js b/addons/web/static/src/views/view_compiler.js index 6f5c90ee3a1..c34815ac0d8 100644 --- a/addons/web/static/src/views/view_compiler.js +++ b/addons/web/static/src/views/view_compiler.js @@ -345,6 +345,9 @@ export class ViewCompiler { button.setAttribute(name, toStringExpression(value)); } } + if (el.hasAttribute("data-hotkey")) { + button.setAttribute("hotkey", toStringExpression(el.getAttribute("data-hotkey"))); + } button.setAttribute("clickParams", JSON.stringify(clickParams)); combineAttributes( diff --git a/addons/web/static/tests/views/form/form_view_tests.js b/addons/web/static/tests/views/form/form_view_tests.js index 5bec517bc41..41e0556dc4b 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -3014,6 +3014,35 @@ QUnit.module("Views", (hooks) => { assert.verifySteps(["get_views", "onchange", "create", "read", "execute_action", "read"]); }); + QUnit.test("buttons with data-hotkey attribute", async function (assert) { + const mockedActionService = { + start() { + return { + doActionButton(params) { + assert.step(params.name); + }, + }; + }, + }; + serviceRegistry.add("action", mockedActionService, { force: true }); + + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+