summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-04-05 09:25:02 +0200
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit2a40c78a8b529828fc8671d362dcf80e0f68b631 (patch)
treec78c5bff785d447b8a0b36b1e721306434d7b77b /addons/web/static/src/js/fields
parent920df597d3d7174723736a395e94dc8ff413c70b (diff)
[FIX] web: fix rendering issue with fieldselection on m2o
Before this commit, the FieldSelection did not work properly in edit mode with a many2one. This was because it did not take the correct value into account, and the test did not notice it, so both had to be fixed.
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js47
1 files changed, 13 insertions, 34 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index 4ae30264ff0..1946cfeb529 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -1337,7 +1337,6 @@ var FieldSelection = AbstractField.extend({
*/
init: function () {
this._super.apply(this, arguments);
- this.values = [];
if (this.field.type === 'many2one') {
this.values = this.record.specialData[this.name];
} else {
@@ -1353,34 +1352,23 @@ var FieldSelection = AbstractField.extend({
//--------------------------------------------------------------------------
/**
- * Format the value to a valid string
- *
- * @override
- * @private
- * @param {any} value
- * @returns {string}
- */
- _formatValue: function (value) {
- if (this.field.type === 'many2one') {
- var options = _.extend({}, this.nodeOptions);
- return field_utils.format.many2one(value, this.field, this.recordData, options);
- } else {
- return this._super(value);
- }
- },
- /**
* @override
* @private
*/
_renderEdit: function () {
- this.$el.empty();
- for (var i = 0 ; i < this.values.length ; i++) {
- this.$el.append($('<option/>', {
- value: JSON.stringify(this.values[i][0]),
- html: this.values[i][1]
- }));
+ if (!this.$el.children().length) {
+ for (var i = 0 ; i < this.values.length ; i++) {
+ this.$el.append($('<option/>', {
+ value: JSON.stringify(this.values[i][0]),
+ html: this.values[i][1]
+ }));
+ }
}
- this.$el.val(JSON.stringify(this._parseValue(this.value)));
+ var value = this.value;
+ if (this.field.type === 'many2one' && value) {
+ value = value.data.id;
+ }
+ this.$el.val(JSON.stringify(value));
},
/**
* @override
@@ -1389,16 +1377,6 @@ var FieldSelection = AbstractField.extend({
_renderReadonly: function () {
this.$el.empty().html(this._formatValue(this.value));
},
- /**
- * @override
- * @private
- */
- _reset: function () {
- this._super.apply(this, arguments);
- if (this.field.type === 'many2one') {
- this.value = this.value.data.id;
- }
- },
//--------------------------------------------------------------------------
// Handlers
@@ -1407,6 +1385,7 @@ var FieldSelection = AbstractField.extend({
/**
* The small slight difficulty is that we have to set the value differently
* depending on the field type.
+ *
* @private
*/
_onChange: function () {