From 09ec63966175b8e6f8d896c71b8a3f1646dfb2ca Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 25 Nov 2015 16:45:06 +0100 Subject: [PATCH] [ADD] form_editor: whitelisting of fields Automatically whitelist fields added to a website_form through the form editor. Ideally fields *removed* from a form should be removed from the whitelist, but since we don't/can't keep track of the website's form, there's no way to know if a field is needed by multiple forms and thus no way to remove them. Plus that would require way more source-tracking than just whitelisting all the form's fields, I don't know if snippet widgets can track the removal of elements from a page (easily anyway). --- static/src/js/website_form_editor.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/static/src/js/website_form_editor.js b/static/src/js/website_form_editor.js index 71085f2cdd2..1b93eefaeb5 100644 --- a/static/src/js/website_form_editor.js +++ b/static/src/js/website_form_editor.js @@ -352,6 +352,22 @@ odoo.define('website_form_editor', function (require) { }, clean_for_save: function () { + var model = this.$target.data('model_name'); + // because apparently this can be called on the wrong widget and + // we may not have a model, or fields... + if (model) { + // we may be re-whitelisting already whitelisted fields. Doesn't + // really matter. + var fields = this.$target.find('input.form-field[name=email_to], .form-field:not(.o_website_form_custom) :input').map(function (_, node) { + return node.getAttribute('name'); + }).get(); + if (fields.length) { + // ideally we'd only do this if saving the form + // succeeds... but no idea how to do that + new Model('ir.model.fields').call('formbuilder_whitelist', [model, _.uniq(fields)]); + } + } + // Prevent saving of the error colors // TODO: would be better on Edit this.$target.find('.has-error').removeClass('has-error'); @@ -482,4 +498,4 @@ odoo.define('website_form_editor', function (require) { } }); -}); \ No newline at end of file +});