From 6901adbe9851f62f451f272d629ede6e4dcb71e8 Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Tue, 29 Oct 2019 10:35:41 +0000 Subject: [PATCH] [FIX] website_form: multiple input files with same name By default, the name of a file input field is 'Custom File Upload'. If there are two fields with the same name, then they both end up in self.form_fields with the name 'Custom File Upload[0]', and their values are concatenated, which are file objects. So the concatenation of two files is a String, ('[object File],[object File]'), because JavaScript. (And if you don't like it you don't like the web nor human progress.) The resulting bug is that instead of adding attachments to the created record, it adds the string message to the notes. Adding the outer loop index disambiguates the names, so that all attachments are created as intended. opw 2092653 closes odoo/odoo#39674 X-original-commit: 5df3f662dc9f7e3030a899a6f4196245083ad415 Signed-off-by: Nans Lefebvre (len) --- addons/website_form/static/src/js/website_form.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/website_form/static/src/js/website_form.js b/addons/website_form/static/src/js/website_form.js index f67565e3c15..84453469351 100644 --- a/addons/website_form/static/src/js/website_form.js +++ b/addons/website_form/static/src/js/website_form.js @@ -91,12 +91,12 @@ odoo.define('website_form.animation', function (require) { // Prepare form inputs this.form_fields = this.$target.serializeArray(); - _.each(this.$target.find('input[type=file]'), function (input) { + $.each(this.$target.find('input[type=file]'), function (outer_index, input) { $.each($(input).prop('files'), function (index, file) { // Index field name as ajax won't accept arrays of files // when aggregating multiple files into a single field value self.form_fields.push({ - name: input.name + '[' + index + ']', + name: input.name + '[' + outer_index + '][' + index + ']', value: file }); });