[IMP] web: add the raw value of selection fields
Task 2327599 It is used in the selector of a tour to know the type of a document.
This commit is contained in:
@@ -2959,11 +2959,7 @@ var FieldSelection = AbstractField.extend({
|
||||
style: disabled ? "display: none" : "",
|
||||
}));
|
||||
}
|
||||
var value = this.value;
|
||||
if (this.field.type === 'many2one' && value) {
|
||||
value = value.data.id;
|
||||
}
|
||||
this.$el.val(JSON.stringify(value));
|
||||
this.$el.val(JSON.stringify(this._getRawValue()));
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
@@ -2971,6 +2967,14 @@ var FieldSelection = AbstractField.extend({
|
||||
*/
|
||||
_renderReadonly: function () {
|
||||
this.$el.empty().text(this._formatValue(this.value));
|
||||
this.$el.attr('raw-value', this._getRawValue());
|
||||
},
|
||||
_getRawValue: function() {
|
||||
var raw_value = this.value;
|
||||
if (this.field.type === 'many2one' && raw_value) {
|
||||
raw_value = raw_value.data.id;
|
||||
}
|
||||
return raw_value;
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
|
||||
@@ -997,7 +997,7 @@ QUnit.module('relational_fields', {
|
||||
});
|
||||
|
||||
QUnit.test('widget selection, edition and on many2one field', async function (assert) {
|
||||
assert.expect(19);
|
||||
assert.expect(21);
|
||||
|
||||
this.data.partner.onchanges = {product_id: function () {}};
|
||||
this.data.partner.records[0].product_id = 37;
|
||||
@@ -1024,10 +1024,14 @@ QUnit.module('relational_fields', {
|
||||
assert.containsNone(form.$('.o_form_view'), 'select');
|
||||
assert.strictEqual(form.$('.o_field_widget[name=product_id]').text(), 'xphone',
|
||||
"should have rendered the many2one field correctly");
|
||||
assert.strictEqual(form.$('.o_field_widget[name=product_id]').attr('raw-value'), '37',
|
||||
"should have set the raw-value attr for many2one field correctly");
|
||||
assert.strictEqual(form.$('.o_field_widget[name=trululu]').text(), '',
|
||||
"should have rendered the unset many2one field correctly");
|
||||
assert.strictEqual(form.$('.o_field_widget[name=color]').text(), 'Red',
|
||||
"should have rendered the selection field correctly");
|
||||
assert.strictEqual(form.$('.o_field_widget[name=color]').attr('raw-value'), 'red',
|
||||
"should have set the raw-value attr for selection field correctly");
|
||||
|
||||
await testUtils.form.clickEdit(form);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user