[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.
This commit is contained in:
Alexandre Kühn
2017-11-24 13:09:10 +01:00
parent 0a3a5919f9
commit fb6c9c2443
5 changed files with 62 additions and 5 deletions
@@ -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);
},
});