From f13a8afdbc32098623bcfa124bf23d7308496455 Mon Sep 17 00:00:00 2001 From: "Louis (loco)" Date: Thu, 26 Oct 2023 13:53:35 +0200 Subject: [PATCH] [FIX] website: re-render the visibility selector on field label change Steps to reproduce the bug: - Add a form on the website. - Add two fields on the form ("A" and "B"). - Change the conditional visibility of "B" and put it to "Visible only if". - Change the label of "B" and set it to "A". - Try to change the dependent field. -> "A" is still on the list of the eligible dependent fields. It should not be the case as setting this field as a dependent field would create a circular dependency. To solve the problem, the file visibility selector is rerendered after modifying a field label. Because of the `_findCircular()` check at the rerendering, the problematic field will not be displayed in the list of of the eligible dependent fields. task-3291044 closes odoo/odoo#140928 X-original-commit: 788218dff61e65f2213c31ebc660183ef3e73087 Signed-off-by: Arthur Detroux (ard) Signed-off-by: Colin Louis (loco) --- .../static/src/snippets/s_website_form/options.js | 7 +++++++ .../static/tests/tours/website_form_editor.js | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/addons/website/static/src/snippets/s_website_form/options.js b/addons/website/static/src/snippets/s_website_form/options.js index 0540df3126e..d772f29a13c 100644 --- a/addons/website/static/src/snippets/s_website_form/options.js +++ b/addons/website/static/src/snippets/s_website_form/options.js @@ -1031,6 +1031,13 @@ options.registry.WebsiteFieldEditor = FieldEditor.extend({ dependentEl.dataset.visibilityDependency = value; } } + + if (!previewMode) { + // As the field label changed, the list of available visibility + // dependencies needs to be updated in order to not propose a + // field that would create a circular dependency. + this.rerender = true; + } } }, /** diff --git a/addons/website/static/tests/tours/website_form_editor.js b/addons/website/static/tests/tours/website_form_editor.js index adf9de52a4b..d4ed78e1280 100644 --- a/addons/website/static/tests/tours/website_form_editor.js +++ b/addons/website/static/tests/tours/website_form_editor.js @@ -208,6 +208,19 @@ trigger: "we-customizeblock-option.snippet-option-WebsiteFieldEditor we-select:contains('Visibility'):has(we-toggler:contains('Always Visible'))", run: () => null, }, + ...addCustomField("char", "text", "Conditional Visibility Check 5", false), + ...addCustomField("char", "text", "Conditional Visibility Check 6", false), + ...selectButtonByData("data-set-visibility='conditional'"), + { + content: "Change the label of 'Conditional Visibility Check 6' and change it to 'Conditional Visibility Check 5'", + trigger: 'we-input[data-set-label-text] input', + run: "text Conditional Visibility Check 5", + }, + { + content: "Check that 'Conditional Visibility Check 5' is not in the list of the renamed field", + trigger: "we-customizeblock-option.snippet-option-WebsiteFieldEditor we-select[data-name='hidden_condition_opt']:not(:has(we-button:contains('Conditional Visibility Check 5')))", + run: () => null, + }, ...addExistingField('email_cc', 'text', 'Test conditional visibility', false, {visibility: CONDITIONALVISIBILITY, condition: 'odoo'}), ...addExistingField('date', 'text', 'Test Date', true),