From 8e75dfca3bcefb92688680d5bf28da6ddeab44d2 Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Fri, 13 Oct 2023 16:09:24 +0200 Subject: [PATCH] [FIX] website: set URL when picking from drop-down menu Steps: - In website, click on a link to edit it - Type "/" in the LinkTools URL input field - Pick a URL among the suggested ones The chosen URL was supposed to be applied to the link, but it is not. The same applies for the LinkDialog (create a link with the "/link" command). Reason: It might be a little confusing, but the `_onURLInput` method actually means "update UI according to the URL" (more specifically, display/hide the "Open In New Window" and "Autoconvert To Relative Link" buttons). The `__onURLInput` (two underscores) method, on the other hand, is the actual handler for input events in the URL field. In this case, picking a URL from a drop-down menu needs the same treatment as inputting text, that is, the `state.url` property must be set to the new value. task-3552700 closes odoo/odoo#140061 Signed-off-by: Antoine Guenet (age) --- addons/website/static/src/js/editor/editor.js | 1 + .../website/static/src/js/editor/widget_link.js | 2 +- addons/website/static/tests/tours/link_tools.js | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/addons/website/static/src/js/editor/editor.js b/addons/website/static/src/js/editor/editor.js index 37608087fdf..e0bbddea3b4 100644 --- a/addons/website/static/src/js/editor/editor.js +++ b/addons/website/static/src/js/editor/editor.js @@ -18,6 +18,7 @@ patch(LinkDialog.prototype, { async start() { const options = { body: this.$link && this.$link[0].ownerDocument.body, + urlChosen: () => this.__onURLInput(), }; const result = await super.start(...arguments); wUtils.autocompleteWithPages(this.rpc.bind(this), this.$el.find('input[name="url"]'), options); diff --git a/addons/website/static/src/js/editor/widget_link.js b/addons/website/static/src/js/editor/widget_link.js index 5bc26ac4401..98a9c309b39 100644 --- a/addons/website/static/src/js/editor/widget_link.js +++ b/addons/website/static/src/js/editor/widget_link.js @@ -94,7 +94,7 @@ patch(LinkTools.prototype, { * @private */ _onAutocompleteClose() { - this._onURLInput(); + this.__onURLInput(); }, /** * @override diff --git a/addons/website/static/tests/tours/link_tools.js b/addons/website/static/tests/tours/link_tools.js index 1e14c78a18e..5659721b3c7 100644 --- a/addons/website/static/tests/tours/link_tools.js +++ b/addons/website/static/tests/tours/link_tools.js @@ -289,10 +289,25 @@ wTourUtils.registerWebsitePreviewTour('link_tools', { throw new Error("Tour step failed"); } } + }, + // 10.Pick a URL with auto-complete + { + content: "Enter partial URL", + trigger: "#o_link_dialog_url_input", + run: 'text /contact' + }, + { + content: "Pick '/contactus", + trigger: "ul.ui-autocomplete li div:contains('/contactus (Contact Us)')", + }, + { + content: "Check that links's href and label were updated", + trigger: "iframe .s_text_image p a[href='/contactus']:contains('/contactus')", + run: () => null, }, ...wTourUtils.clickOnSave(), ...wTourUtils.clickOnEditAndWaitEditMode(), - // 10. Add mega menu with Cards template and edit URL on text-selected card. + // 11. Add mega menu with Cards template and edit URL on text-selected card. wTourUtils.clickOnElement("menu link", "iframe header .nav-item a"), wTourUtils.clickOnElement("'Edit menu' icon", "iframe .o_edit_menu_popover .fa-sitemap"), {