summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2019-05-24 10:16:46 +0000
committerJulien Mougenot <jum@odoo.com>2019-06-03 15:01:57 +0000
commitd7d7d92e92aa4bc5d81c77b41c8e41f4ee479777 (patch)
treecbaff2d61dc39020358c2b27679fd12a15bcd6f7
parent6028d91a26f093baa05faf8b5da0a708eca45f4d (diff)
[FIX] web: binary fields correctly resets
When uploading a file to a binary file, then clicking on the "clear" button, then reuploading the same file... Before this commit: The actual input of the field was only changed on user input. This means that the "clear" action didn't reset the actual value of the input, and the browser's default behaviour when getting the same path twice is not to change anything. In the use case, you couldn't upload the same file until you uploaded another one. After this commit: The "clear" action now also clears the value, allowing reuploading the same file over again. closes odoo/odoo#33843 Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js1
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js29
2 files changed, 30 insertions, 0 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index fd156f2d00b..97f3c056c5d 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -1228,6 +1228,7 @@ var AbstractFieldBinary = AbstractField.extend({
}
},
on_clear: function () {
+ this.$('.o_input_file').val('');
this.set_filename('');
this._setValue(false);
this._render();
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js
index d08f898dba1..334bb6d081c 100644
--- a/addons/web/static/tests/fields/basic_fields_tests.js
+++ b/addons/web/static/tests/fields/basic_fields_tests.js
@@ -1578,6 +1578,35 @@ QUnit.module('basic_fields', {
list.destroy();
});
+ QUnit.test("binary fields input value is empty whean clearing after uploading", function (assert) {
+ assert.expect(2);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<field name="document" filename="foo"/>' +
+ '<field name="foo"/>' +
+ '</form>',
+ res_id: 1,
+ });
+
+ form.$buttons.find('.btn:contains("Edit")').click();
+ // // We need to convert the input type since we can't programmatically set the value of a file input
+ form.$('.o_input_file').attr('type', 'text').val('coucou.txt');
+
+ assert.strictEqual(form.$('.o_input_file').val(), 'coucou.txt',
+ "input value should be changed to \"coucou.txt\"");
+
+ form.$('.o_field_binary_file > .o_clear_file_button').click();
+
+ assert.strictEqual(form.$('.o_input_file').val(), '',
+ "input value should be empty");
+
+ form.destroy();
+ });
+
QUnit.test('field text in editable list view', function (assert) {
assert.expect(1);