diff options
| author | Aaron Bohy <aab@odoo.com> | 2020-05-12 09:33:07 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2020-05-12 13:43:53 +0000 |
| commit | efe10976a4ae085e905487fdd3479e70788b653a (patch) | |
| tree | 34b5fbf4de7c7e559e7371bf5f81f88d503b361e /addons/web/static/src | |
| parent | e02a4b93e514e5b8ef457ea651e28ed84340bfeb (diff) | |
[FIX] web: correctly update input field after onchange
In a form view, have an x2many list with two fields A and B (e.g.
A is a many2one, and B is a char). There is an onchange on the
x2many that is triggered when the user sets A, and that sets B.
In this scenario, let's assume that the user first writes something
in B, but directly deletes it. Then, he sets A. Before this commit,
in this situation, B wasn't updated with the value returned by the
onchange.
Indeed, B's field widget was still flagged as 'isDirty', because
the user interacted with it, but it didn't commit its value, as it
hasn't actually changed. Basically, it remained flagged as 'isDirty'
forever, and thus couldn't be updated with the value returned by
the onchange.
This commit ensures that the 'isDirty' status is correctly updated
when the change is actually undone.
Task 1958793
closes odoo/odoo#51085
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Co-authored-by: pka-odoo <pka@odoo.com>
Co-authored-by: Mohammed Shekha <msh@odoo.com>
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/fields/abstract_field.js | 17 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/abstract_field_owl.js | 17 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 2 |
3 files changed, 29 insertions, 7 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js index ab6f226a66e..16e928ea288 100644 --- a/addons/web/static/src/js/fields/abstract_field.js +++ b/addons/web/static/src/js/fields/abstract_field.js @@ -404,6 +404,18 @@ var AbstractField = Widget.extend({ return `text-${decoration.split('-')[1]}`; }, /** + * Compares the given value with the last value that has been set. + * Note that we compare unparsed values. Handles the special case where no + * value has been set yet, and the given value is the empty string. + * + * @private + * @param {any} value + * @returns {boolean} true iff values are the same + */ + _isLastSetValue: function (value) { + return this.lastSetValue === value || (this.value === false && value === ''); + }, + /** * This method check if a value is the same as the current value of the * field. For example, a fieldDate widget might want to use the moment * specific value isSame instead of ===. @@ -499,9 +511,8 @@ var AbstractField = Widget.extend({ * @returns {Promise} */ _setValue: function (value, options) { - // we try to avoid doing useless work, if the value given has not - // changed. Note that we compare the unparsed values. - if (this.lastSetValue === value || (this.value === false && value === '')) { + // we try to avoid doing useless work, if the value given has not changed. + if (this._isLastSetValue(value)) { return Promise.resolve(); } this.lastSetValue = value; diff --git a/addons/web/static/src/js/fields/abstract_field_owl.js b/addons/web/static/src/js/fields/abstract_field_owl.js index f97faae35ed..43e3d468d78 100644 --- a/addons/web/static/src/js/fields/abstract_field_owl.js +++ b/addons/web/static/src/js/fields/abstract_field_owl.js @@ -454,6 +454,18 @@ odoo.define('web.AbstractFieldOwl', function (require) { return `text-${decoration.split('-')[1]}`; } /** + * Compares the given value with the last value that has been set. + * Note that we compare unparsed values. Handles the special case where no + * value has been set yet, and the given value is the empty string. + * + * @private + * @param {any} value + * @returns {boolean} true iff values are the same + */ + _isLastSetValue(value) { + return this._lastSetValue === value || (this.value === false && value === ''); + } + /** * This method check if a value is the same as the current value of the * field. For example, a fieldDate component might want to use the moment * specific value isSame instead of ===. @@ -498,9 +510,8 @@ odoo.define('web.AbstractFieldOwl', function (require) { * @returns {Promise} */ _setValue(value, options) { - // we try to avoid doing useless work, if the value given has not - // changed. Note that we compare the unparsed values. - if (this._lastSetValue === value || (this.value === false && value === '')) { + // we try to avoid doing useless work, if the value given has not changed. + if (this._isLastSetValue(value)) { return Promise.resolve(); } this._lastSetValue = value; diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index bf225d7ea99..d5f1f1074d4 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -326,7 +326,7 @@ var InputField = DebouncedField.extend({ * @private */ _onInput: function () { - this.isDirty = true; + this.isDirty = !this._isLastSetValue(this.$input.val()); this._doDebouncedAction(); }, /** |
