From d96aa1784f71682170bd3f4624c05af1a63bc2fb Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Mon, 26 Jun 2023 07:56:37 +0000 Subject: [PATCH] [FIX] website: fix anchor selector not updating Steps to reproduce the bugs: - Add a banner on the homepage - Click on the "create a link to target this section" button. - Edit the anchor name to "bannerAnchor". - Drop the image-text snippet. - Double click on the button inside the snippet. - Choose the homepage as the URL ("/") - Open the "Page Anchor" select, choose "#bannerAnchor" - Validate the changes. - Double Click on the snippet button again. - First bug: The URL properly shows "/#bannerAnchor" but the page anchor select does not show anything. - Open the page anchor select again. - Second Bug: the "bannerAnchor" option does not appear as a choice. This commit fixes the two bugs described above. task-3378864 closes odoo/odoo#128345 X-original-commit: 62ed601bcf53fd6572118e742a5e27f7f3c7b6f6 Signed-off-by: Quentin Smetz (qsm) Signed-off-by: Benjamin Vray (bvr) --- .../website/static/src/js/editor/widget_link.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/website/static/src/js/editor/widget_link.js b/addons/website/static/src/js/editor/widget_link.js index 65b9ddb1d2b..415d512d1fb 100644 --- a/addons/website/static/src/js/editor/widget_link.js +++ b/addons/website/static/src/js/editor/widget_link.js @@ -54,8 +54,19 @@ weWidgets.LinkTools.include({ if ($selectMenu.data("anchor-for") !== urlInputValue) { // avoid useless query $pageAnchor.toggleClass('d-none', !isFromWebsite); $selectMenu.empty(); - const always = () => $pageAnchor.find('we-toggler').text('\u00A0'); - wUtils.loadAnchors(urlInputValue, this.$editable[0].ownerDocument.body).then(anchors => { + const always = () => { + const anchor = `#${urlInputValue.split('#')[1]}`; + let weTogglerText = '\u00A0'; + if (anchor) { + const weButtonEls = $selectMenu[0].querySelectorAll('we-button'); + if (Array.from(weButtonEls).some(el => el.textContent === anchor)) { + weTogglerText = anchor; + } + } + $pageAnchor[0].querySelector('we-toggler').textContent = weTogglerText; + }; + const urlWithoutHash = urlInputValue.split("#")[0]; + wUtils.loadAnchors(urlWithoutHash, this.$editable[0].ownerDocument.body).then(anchors => { for (const anchor of anchors) { const $option = $(''); $option.text(anchor);