[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) <aab@odoo.com>
This commit is contained in:
Joseph Caburnay
2023-02-03 08:24:42 +01:00
parent 2b1df29095
commit fda7805200
2 changed files with 9 additions and 1 deletions
@@ -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();
}
+7 -1
View File
@@ -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");