From e70a2eb0f6f11400ae33fc4382b5be7a3fc421ab Mon Sep 17 00:00:00 2001 From: "Louis (loco)" Date: Wed, 13 Dec 2023 10:44:39 +0100 Subject: [PATCH] [FIX] website: enable to add a description on form field Steps to reproduce: - Add a "Form" snippet on the website. - Select the first field. - Try to toggle the "description" option of the field. -> Problem: there is no description added on the field. The problems appeared since [this PR] and comes more precisely from [this commit]. The problem is that one condition required to fill the `default_description` parameter is that `field.type === "description"`. This should not be the case. Indeed, here was the flow before [this commit]; When the user toggled the description option, `toggleDescription` assigned `field.description` to `true`. The field was then rendered trough `renderField()`. During this rendering, the system called the `website.form_field_description` template through `website.form_field` independently of the field type. Because `field.description` was set to `true`, a `div` with the description "Describe your field here." was added on the rendered field. To solve the problem, the `field.type === "description"` condition has been removed as a condition to set the `default_description` parameter. Now, as it was the case before [this commit], this parameter is filled either if `field.description` is set, either if the field name is `email_cc` or `email_to`. The error probably comes from the fact that the name of the template used to render the field is `"website.form_field_" + field.type`. As the name of the template in charge of rendering the description is `website.form_field_description`, the author probably thought that this template should only be called when `field.type === "description"`. This is not the case; the template `website.form_field_description` is always called when rendering a field (independently of the field type through the template `website.form_field`) but is only relevant if `default_description` is set. Note that this fix fixes also another bug: - Add a "Form" snippet on the website. - Add a field which is of type "Cc". -> Problem: there should be a description of type "Separate email addresses with a comma." on the field. This commit also adapts the `website_form_editor_tour` tour to verify that the description option works as wanted. [this PR]: https://github.com/odoo/odoo/pull/130467 [this commit]: https://github.com/odoo/odoo/commit/363251986dcd753796b4b037a2da2e118b3e8e35 opw-3630348 opw-3604548 closes odoo/odoo#146115 Signed-off-by: Romain Derie (rde) --- .../src/snippets/s_website_form/options.js | 10 +++---- .../static/tests/tours/website_form_editor.js | 27 ++++++++++++++----- 2 files changed, 25 insertions(+), 12 deletions(-) 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 d772f29a13c..97387d3023e 100644 --- a/addons/website/static/src/snippets/s_website_form/options.js +++ b/addons/website/static/src/snippets/s_website_form/options.js @@ -175,12 +175,10 @@ const FormEditor = options.Class.extend({ if (field.custom && !field.string) { params.field.string = field.name; } - if (field.type === "description") { - if (field.description) { - params.default_description = _t("Describe your field here."); - } else if (["email_cc", "email_to"].includes(field.name)) { - params.default_description = _t("Separate email addresses with a comma."); - } + if (field.description) { + params.default_description = _t("Describe your field here."); + } else if (["email_cc", "email_to"].includes(field.name)) { + params.default_description = _t("Separate email addresses with a comma."); } const template = document.createElement('template'); template.content.append(renderToElement("website.form_field_" + field.type, params)); diff --git a/addons/website/static/tests/tours/website_form_editor.js b/addons/website/static/tests/tours/website_form_editor.js index d4ed78e1280..dd4ac97428a 100644 --- a/addons/website/static/tests/tours/website_form_editor.js +++ b/addons/website/static/tests/tours/website_form_editor.js @@ -222,6 +222,11 @@ run: () => null, }, ...addExistingField('email_cc', 'text', 'Test conditional visibility', false, {visibility: CONDITIONALVISIBILITY, condition: 'odoo'}), + { + content: "Ensure that the description has correctly been added on the field", + trigger: "iframe .s_website_form_field:contains('Test conditional visibility') .s_website_form_field_description", + isCheck: true, + }, ...addExistingField('date', 'text', 'Test Date', true), @@ -434,11 +439,11 @@ { content: "Check that field B prefill text is set", trigger: `iframe ${triggerFieldByLabel("field B")}:has(input[value="prefilled"])`, - run: () => null, // it's a check + isCheck: true, }, { content: "Check that field A is visible", trigger: `iframe .s_website_form:has(${triggerFieldByLabel("field A")}:visible)`, - run: () => null, // it's a check + isCheck: true, }, // A) Check that if we edit again and save again the default value is // not deleted. @@ -468,7 +473,7 @@ `:has(${triggerFieldByLabel("field A")}:not(:visible))` + `:has(${triggerFieldByLabel("field B")}` + `:has(input[value="prefilled"]):not(:visible))`, - run: () => null, // it's a check + isCheck: true, }, { content: "Type something in field C", trigger: `iframe ${triggerFieldByLabel("field C")} input`, @@ -477,7 +482,7 @@ content: "Check that fields A and B are visible", trigger: `iframe .s_website_form:has(${triggerFieldByLabel("field B")}:visible)` + `:has(${triggerFieldByLabel("field A")}:visible)`, - run: () => null, // it's a check + isCheck: true, }, // Have field A's visibility tied to field B containing something, @@ -506,7 +511,7 @@ content: "Check that field B is visible, but field A is not", trigger: `iframe .s_website_form:has(${triggerFieldByLabel("field B")}:visible)` + `:has(${triggerFieldByLabel("field A")}:not(:visible))`, - run: () => null, // it's a check + isCheck: true, }, { content: "Insert 'peek-a-boo' in field B", trigger: `iframe ${triggerFieldByLabel("field B")} input`, @@ -514,7 +519,7 @@ }, { content: "Check that field A is visible", trigger: `iframe .s_website_form:has(${triggerFieldByLabel("field A")}:visible)`, - run: () => null, // it's a check + isCheck: true, }, ...wTourUtils.clickOnEditAndWaitEditMode(), { @@ -533,6 +538,16 @@ ...addCustomField("char", "text", '""', false), ...addCustomField("char", "text", "``", false), ...addCustomField("char", "text", "\\", false), + + // Ensure that the description option is working as wanted. + ...addCustomField("char", "text", "Check description option", false), + wTourUtils.changeOption("WebsiteFieldEditor", "we-button[data-toggle-description] we-checkbox"), + { + content: "Ensure that the description has correctly been added on the field", + trigger: "iframe .s_website_form_field:contains('Check description option') .s_website_form_field_description", + isCheck: true, + }, + ...wTourUtils.clickOnSave(), { content: 'Verify that the recipient email has been saved',