diff --git a/addons/web/static/src/js/views/form_relational_widgets.js b/addons/web/static/src/js/views/form_relational_widgets.js index a6ffcd3d058..81752617940 100644 --- a/addons/web/static/src/js/views/form_relational_widgets.js +++ b/addons/web/static/src/js/views/form_relational_widgets.js @@ -513,9 +513,7 @@ var AbstractManyField = common.AbstractField.extend({ this.set('value', []); this.starting_ids = []; this.has_not_committed_changes = false; - this.view.on("load_record", this, function () { - self.starting_ids = self.get('value').slice(); - }); + this.view.on("load_record", this, this._on_load_record); this.dataset.on('dataset_changed', this, function() { self.has_not_committed_changes = true; // the editable lists change the dataset without call AbstractManyField methods @@ -529,6 +527,10 @@ var AbstractManyField = common.AbstractField.extend({ }); }, + _on_load_record: function (record) { + this.starting_ids = record.id ? record[this.name].slice() : []; + }, + set_value: function(ids) { ids = (ids || []).slice(); if (_.find(ids, function(id) { return typeof(id) === "string"; } )) { @@ -723,6 +725,11 @@ var AbstractManyField = common.AbstractField.extend({ is_false: function() { return _(this.get('value')).isEmpty(); }, + + destroy: function () { + this.view.off("load_record", this, this._on_load_record); + this._super(); + } });