diff options
| author | Alexandre Kühn <aku@odoo.com> | 2017-11-09 13:12:55 +0100 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2017-11-24 13:09:10 +0100 |
| commit | fb6c9c24434c941383ffd73ab3056cafd7740c52 (patch) | |
| tree | 37d392d284ae15ea31e5e43fc1b048e4f80a644a /addons/web/static/tests/fields/basic_fields_tests.js | |
| parent | 0a3a5919f9a5761e4482439aa604b9c919327ef0 (diff) | |
[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.
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 39 |
1 files changed, 38 insertions, 1 deletions
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: '<form string="Partners">' + + '<sheet>' + + '<group>' + + '<field name="foo"/>' + + '<field name="foo2"/>' + + '</group>' + + '</sheet>' + + '</form>', + 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); |
