[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) <qsm@odoo.com>
Signed-off-by: Benjamin Vray (bvr) <bvr@odoo.com>
This commit is contained in:
Benjamin Vray
2023-07-13 10:46:16 +02:00
parent 9726a414e9
commit d96aa1784f
@@ -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 = $('<we-button class="dropdown-item">');
$option.text(anchor);