From fb6c9c24434c941383ffd73ab3056cafd7740c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Ku=CC=88hn?= Date: Thu, 9 Nov 2017 13:12:55 +0100 Subject: [IMP] web: FieldChar trim its value by default With this commit, we change the behaviour of the web client with respect to spaces in char fields. Most of the time, starting and ending spaces have no value, and worse, make the data not so reliable. After this commit, field char will trim by default (so, if the user input a char as ' abc ', the string 'abc' will be sent to the server instead). Note that this only applies when the value of the field is changed. If someone open a form view, then switches to edit mode and save, nothing will change. This is the desired behavior most of the time. However, in some rare cases, this is actually harmful. For example, if we trim the 'decimal_point' field, it will not be possible to enter a whitespace as decimal separator. In those cases, we introduce a new attribute 'trim', which allow the developer to desactivate that feature. --- .../web/static/tests/fields/basic_fields_tests.js | 39 +++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 35431904cec..0e1bb096e50 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -24,7 +24,7 @@ QUnit.module('basic_fields', { date: {string: "A date", type: "date", searchable: true}, datetime: {string: "A datetime", type: "datetime", searchable: true}, display_name: {string: "Displayed name", type: "char", searchable: true}, - foo: {string: "Foo", type: "char", default: "My little Foo Value", searchable: true}, + foo: {string: "Foo", type: "char", default: "My little Foo Value", searchable: true, trim: true}, bar: {string: "Bar", type: "boolean", default: true, searchable: true}, txt: {string: "txt", type: "text", default: "My little txt Value\nHo-ho-hoooo Merry Christmas"}, int_field: {string: "int_field", type: "integer", sortable: true, searchable: true}, @@ -876,6 +876,43 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('char field trim (or not) characters', function (assert) { + assert.expect(2); + + this.data.partner.fields.foo2 = {string: "Foo2", type: "char", trim: false}; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 1, + viewOptions: { + mode: 'edit', + }, + }); + + form.$('input[name="foo"]').val(' abc ').trigger('input'); + form.$('input[name="foo2"]').val(' def ').trigger('input'); + + form.$buttons.find('.o_form_button_save').click(); + + // edit mode + form.$buttons.find('.o_form_button_edit').click(); + + assert.strictEqual(form.$('input[name="foo"]').val(), 'abc', 'Foo value should have been trimmed'); + assert.strictEqual(form.$('input[name="foo2"]').val(), ' def ', 'Foo2 value should not have been trimmed'); + + form.destroy(); + }); + QUnit.test('input field: change value before pending onchange returns', function (assert) { assert.expect(3); -- cgit v1.2.3