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. --- addons/web/static/src/js/fields/basic_fields.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index a4979848adb..2872be972a5 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -347,6 +347,20 @@ var FieldChar = InputField.extend(TranslatableFieldMixin, { this.$el = this.$el.add(this._renderTranslateButton()); return def; }, + /** + * Trim the value input by the user. + * + * @override + * @private + * @param {any} value + * @param {Object} [options] + */ + _setValue: function (value, options) { + if (this.field.trim) { + value = value.trim(); + } + return this._super(value, options); + }, }); -- cgit v1.2.3