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 de3decfe3e2..23d2330d62d 100644 --- a/addons/website/static/src/snippets/s_website_form/options.js +++ b/addons/website/static/src/snippets/s_website_form/options.js @@ -12,6 +12,7 @@ import { unique } from "@web/core/utils/arrays"; const qweb = core.qweb; const _t = core._t; +let currentActionName; const FormEditor = options.Class.extend({ //---------------------------------------------------------------------- @@ -335,6 +336,7 @@ options.registry.WebsiteFormEditor = FormEditor.extend({ const targetModelName = this.$target[0].dataset.model_name || 'mail.mail'; this.activeForm = this.models.find(m => m.model === targetModelName); + currentActionName = this.activeForm.website_form_label; // Create the Form Action select this.selectActionEl = document.createElement('we-select'); this.selectActionEl.setAttribute('string', 'Action'); @@ -734,6 +736,7 @@ options.registry.WebsiteFormEditor = FormEditor.extend({ } this.$target.find('.s_website_form_field').remove(); this.activeForm = this.models.find(model => model.id === modelId); + currentActionName = this.activeForm.website_form_label; } const formKey = this.activeForm.website_form_key; const formInfo = FormEditorRegistry.get(formKey); @@ -1536,9 +1539,28 @@ options.registry.WebsiteFormFieldModel = DisableOverlayButtonOption.extend({ // Disable delete button for model required fields options.registry.WebsiteFormFieldRequired = DisableOverlayButtonOption.extend({ start: function () { - this.disableButton('remove', _t('This field is mandatory for this Action. You cannot remove it.')); + this.disableButton("remove", _t( + "This field is mandatory for this action. You cannot remove it. Try hiding it with the" + + " 'Visibility' option instead and add it a default value." + )); return this._super.apply(this, arguments); - } + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + */ + async _renderCustomXML(uiFragment) { + const fieldName = this.$target[0] + .querySelector("input.s_website_form_input").getAttribute("name"); + const spanEl = document.createElement("span"); + spanEl.innerText = sprintf(_t( + "The field '%s' is mandatory for the action '%s'."), fieldName, currentActionName); + uiFragment.querySelector("we-alert").appendChild(spanEl); + }, }); // Disable delete and duplicate button for submit diff --git a/addons/website/views/snippets/s_website_form.xml b/addons/website/views/snippets/s_website_form.xml index a3dc44b249f..46c4b93f3fe 100644 --- a/addons/website/views/snippets/s_website_form.xml +++ b/addons/website/views/snippets/s_website_form.xml @@ -67,6 +67,12 @@ +
+ + +
+
@@ -227,9 +233,6 @@
- -
-