From 0447f177ad5671f4903e8854ec2bb644fd1675cb Mon Sep 17 00:00:00 2001 From: fja-odoo Date: Fri, 20 Mar 2020 14:02:47 +0000 Subject: [PATCH] [IMP] website_form: allow to add description to field It is now possible to add a description to any field. Part of: https://github.com/odoo/odoo/pull/47949 task-2011583 --- .../src/snippets/s_website_form/options.js | 19 +++++++++++++++++++ .../static/src/xml/website_form_editor.xml | 10 +++++++--- .../views/snippets/s_website_form.xml | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/addons/website_form/static/src/snippets/s_website_form/options.js b/addons/website_form/static/src/snippets/s_website_form/options.js index 4384aae6bca..944f5562315 100644 --- a/addons/website_form/static/src/snippets/s_website_form/options.js +++ b/addons/website_form/static/src/snippets/s_website_form/options.js @@ -258,6 +258,7 @@ const FieldEditor = FormEditor.extend({ const classList = this.$target[0].classList; const textarea = this.$target[0].querySelector('textarea'); const input = this.$target[0].querySelector('input[type="text"], input[type="email"], input[type="number"], input[type="tel"], input[type="url"], textarea'); + const description = this.$target[0].querySelector('.s_website_form_field_description'); field.placeholder = input && input.placeholder; if (input) { // textarea value has no attribute, date/datetime timestamp property is formated @@ -267,6 +268,7 @@ const FieldEditor = FormEditor.extend({ } // property value is needed for date/datetime (formated date). field.propertyValue = input && input.value; + field.description = description && description.textContent; field.rows = textarea && textarea.rows; field.required = classList.contains('s_website_form_required'); field.modelRequired = classList.contains('s_website_form_model_required'); @@ -790,6 +792,19 @@ options.registry.WebsiteFieldEditor = FieldEditor.extend({ // Options //---------------------------------------------------------------------- + /** + * Add a description to the field input + */ + appendDescription: async function (previewMode, value, params) { + const description = this.$target[0].querySelector('.s_website_form_field_description'); + if (description && value) { + description.textContent = value; + } else { + const field = this._getActiveField(); + field.description = value; + await this._replaceField(field); + } + }, /** * Replace the current field with the custom field selected. */ @@ -902,6 +917,10 @@ options.registry.WebsiteFieldEditor = FieldEditor.extend({ */ _computeWidgetState: function (methodName, params) { switch (methodName) { + case 'appendDescription': { + const description = this.$target[0].querySelector('.s_website_form_field_description'); + return description ? description.textContent : ''; + } case 'customField': return this._isFieldCustom() ? this._getFieldType() : ''; case 'existingField': diff --git a/addons/website_form/static/src/xml/website_form_editor.xml b/addons/website_form/static/src/xml/website_form_editor.xml index 889291c1e7f..eaa67a36437 100644 --- a/addons/website_form/static/src/xml/website_form_editor.xml +++ b/addons/website_form/static/src/xml/website_form_editor.xml @@ -42,6 +42,7 @@
+
@@ -49,6 +50,7 @@ + @@ -62,9 +64,11 @@ - - - + + + + + diff --git a/addons/website_form/views/snippets/s_website_form.xml b/addons/website_form/views/snippets/s_website_form.xml index beec88770d9..f2c58971d86 100644 --- a/addons/website_form/views/snippets/s_website_form.xml +++ b/addons/website_form/views/snippets/s_website_form.xml @@ -102,6 +102,7 @@ +