diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-05-03 15:18:08 +0200 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2017-05-04 09:32:24 +0200 |
| commit | 91d1fd870123e9a56d64e3482e2ead1536230ab7 (patch) | |
| tree | 563147ae00b5aaba3dc080bde43ac7ad8559ad2a /addons/web/static/src/js/fields/basic_fields.js | |
| parent | 7b6c474c203cf2a9c4f8ed7512a944c87cfdea85 (diff) | |
[FIX] web: prevent double onchange in some cases
When we unselect a line in a one2many list, we ask for all fields to
commit their changes (because many fields are debounced, so we may not
know their current last value). This is good, except that it could
trigger an extra field change event, which may in turn trigger a second
onchange.
We solve this issue by improving the _setValue method and delegating the
comparison to a new _isSameValue method.
It is particularly relevant for field types such as integer, which are not
stored as a string.
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index d1569797731..dd87d893cc0 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -264,7 +264,7 @@ var FieldDate = InputField.extend({ if (this.mode === 'edit') { this.datewidget = this._makeDatePicker(); this.datewidget.on('datetime_changed', this, function () { - var value = this._getDateWidgetValue(); + var value = this._getValue(); if ((!value && this.value) || (value && !value.isSame(this.value))) { this._setValue(value); } @@ -295,10 +295,20 @@ var FieldDate = InputField.extend({ * * @private */ - _getDateWidgetValue: function () { + _getValue: function () { return this.datewidget.get_value(); }, - + /** + * @override + * @private + * @param {Moment|false} value + */ + _isSameValue: function (value) { + if (value === false) { + return this.value === false; + } + return value.isSame(this.value); + }, /** * Instantiates a new DateWidget datepicker. * @@ -343,7 +353,7 @@ var FieldDateTime = FieldDate.extend({ * * @private */ - _getDateWidgetValue: function () { + _getValue: function () { var value = this.datewidget.get_value(); return value && value.add(-this.getSession().tzOffset, 'minutes'); }, |
