diff --git a/addons/website/static/src/js/editor/wysiwyg.js b/addons/website/static/src/js/editor/wysiwyg.js index a16de263657..5f90122d625 100644 --- a/addons/website/static/src/js/editor/wysiwyg.js +++ b/addons/website/static/src/js/editor/wysiwyg.js @@ -3,6 +3,7 @@ import Wysiwyg from "web_editor.wysiwyg"; import snippetsEditor from "website.snippet.editor"; import socialMediaOptions from "@website/snippets/s_social_media/options"; +import formOptions from "@website/snippets/s_website_form/options"; /** * Show/hide the dropdowns associated to the given toggles and allows to wait @@ -113,6 +114,8 @@ const WebsiteWysiwyg = Wysiwyg.extend({ // from the accessed website. socialMediaOptions.clearDbSocialValuesCache(); + formOptions.clearAllFormsInfo(); + this._restoreMegaMenus(); this._super.apply(this, arguments); }, 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 f5f592b754d..06668951c3f 100644 --- a/addons/website/static/src/snippets/s_website_form/options.js +++ b/addons/website/static/src/snippets/s_website_form/options.js @@ -14,6 +14,31 @@ const qweb = core.qweb; const _t = core._t; let currentActionName; +const allFormsInfo = new Map(); +const clearAllFormsInfo = () => { + allFormsInfo.clear(); +}; +/** + * Returns the domain of a field. + * + * @private + * @param {HTMLElement} formEl + * @param {String} name + * @param {String} type + * @param {String} relation + * @returns {Object|false} + */ +function _getDomain(formEl, name, type, relation) { + // We need this because the field domain is in formInfo in the + // WebsiteFormEditor but we need it in the WebsiteFieldEditor. + if (!allFormsInfo.get(formEl) || !name || !type || !relation) { + return false; + } + const field = allFormsInfo.get(formEl).fields + .find(el => el.name === name && el.type === type && el.relation === relation); + return field && field.domain; +} + const FormEditor = options.Class.extend({ //---------------------------------------------------------------------- // Private @@ -607,6 +632,7 @@ options.registry.WebsiteFormEditor = FormEditor.extend({ if (!formInfo || !formInfo.fields) { return; } + allFormsInfo.set(this.$target[0], formInfo); const proms = formInfo.fields.map(field => this._fetchFieldRecords(field)); return Promise.all(proms).then(() => { formInfo.fields.forEach(field => { @@ -849,7 +875,8 @@ options.registry.WebsiteFieldEditor = FieldEditor.extend({ this.fields = {}; for (const [fieldName, field] of Object.entries(fields)) { field.name = fieldName; - field.domain = field.domain || []; + const fieldDomain = _getDomain(this.formEl, field.name, field.type, field.relation); + field.domain = fieldDomain || field.domain || []; this.fields[fieldName] = field; } // Create the buttons for the type we-select @@ -1590,3 +1617,7 @@ options.registry.DeviceVisibility.include({ && !this.$target.hasClass('s_website_form_field_hidden'); }, }); + +export default { + clearAllFormsInfo, +};