From fda7805200e471af982a19bb23927892a63a7684 Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Wed, 23 Nov 2022 14:34:25 +0000 Subject: [PATCH] [FIX] web: make the AutoComplete component to emit an event This allows the tour manager to attach an event handler that listens to the "AutoComplete:OPTION_SELECTED" event from components that utilizes AutoComplete, and if that so happens, the tour can proceed to the next step. This change is proposed because of the following bug report: > [aju] https://watch.screencastify.com/v/UBGeNfXEJmCvE963VSnk > planning onboarding tour > creating a resource on the fly by hitting > Enter should validate the step closes odoo/odoo#111798 X-original-commit: dbccea9a983b3a92fe9a299e4c8704158c7019ae Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/core/autocomplete/autocomplete.js | 2 ++ addons/web_tour/static/src/js/tip.js | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/core/autocomplete/autocomplete.js b/addons/web/static/src/core/autocomplete/autocomplete.js index 0e51f26d251..a8ce557ee3f 100644 --- a/addons/web/static/src/core/autocomplete/autocomplete.js +++ b/addons/web/static/src/core/autocomplete/autocomplete.js @@ -143,6 +143,8 @@ export class AutoComplete extends Component { ...params, input: this.inputRef.el, }); + const customEvent = new CustomEvent("AutoComplete:OPTION_SELECTED", { bubbles: true }); + this.root.el.dispatchEvent(customEvent); this.close(); } diff --git a/addons/web_tour/static/src/js/tip.js b/addons/web_tour/static/src/js/tip.js index 9abd746af13..d4c58a2a3eb 100644 --- a/addons/web_tour/static/src/js/tip.js +++ b/addons/web_tour/static/src/js/tip.js @@ -638,7 +638,13 @@ var Tip = Widget.extend({ * @param {string} [run] the run parameter of the tip (only strings are useful) */ Tip.getConsumeEventType = function ($element, run) { - if ($element.hasClass('o_field_many2one') || $element.hasClass('o_field_many2manytags')) { + if ($element.has("input.o-autocomplete--input.o_input").length > 0) { + // Components that utilizes the AutoComplete component is expected to + // contain an input with the class o-autocomplete--input. + // And when an option is selected, the component triggers + // 'AutoComplete:OPTION_SELECTED' event. + return 'AutoComplete:OPTION_SELECTED'; + } else if ($element.hasClass('o_field_many2one') || $element.hasClass('o_field_many2manytags')) { return 'autocompleteselect'; } else if ($element.is("textarea") || $element.filter("input").is(function () { var type = $(this).attr("type");