summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-05-18 10:41:00 +0200
committerAaron Bohy <aab@odoo.com>2017-05-18 13:55:46 +0200
commitabacdd97766d58312917901599c277f62bfbef3a (patch)
tree97366d63090a1761fea20f44d6d810fb5d18f636 /addons/web/static/src/js/fields
parent787daee41f4ccd3d02913f74fb20326d28f80e90 (diff)
[FIX] web: FieldRadio with numerical keys encoded as strings
Before this rev., the FieldRadio didn't work on selection fields with keys like "0", "1"... i.e. strings that can be converted to numerical values. This was due to an automatic conversion of those keys to their numerical value by JQuery, so when the user changed the value, an unknow key was sent to the server (e.g. 1 instead of "1"), causing a crash. This rev. changes the logic a bit so that the keys are no more written in the DOM, but their index in the selection are.
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js23
1 files changed, 12 insertions, 11 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index 7f8cbd2eb45..a7b8559a4f2 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -1785,14 +1785,17 @@ var FieldRadio = FieldSelection.extend({
* @override
*/
_renderEdit: function () {
- this.$("input").prop("checked", false);
- var key;
+ var value;
if (this.field.type === 'many2one') {
- key = this.value && this.value.data.id;
+ value = this.value && this.value.data.id;
} else {
- key = this.value;
+ value = this.value;
}
- this.$('input[data-value="' + key + '"]').prop('checked', true);
+ var index = _.findIndex(this.values, function (option) {
+ return option[0] === value;
+ });
+ this.$("input").prop("checked", false);
+ this.$('input[data-index="' + index + '"]').prop('checked', true);
},
//--------------------------------------------------------------------------
@@ -1804,14 +1807,12 @@ var FieldRadio = FieldSelection.extend({
* @param {MouseEvent} event
*/
_onInputClick: function (event) {
- var res_id = $(event.target).data('value');
+ var index = $(event.target).data('index');
+ var value = this.values[index];
if (this.field.type === 'many2one') {
- var value = _.find(this.values, function (val) {
- return val[0] === res_id;
- });
- this._setValue({id: res_id, display_name: value[1]});
+ this._setValue({id: value[0], display_name: value[1]});
} else {
- this._setValue(res_id);
+ this._setValue(value[0]);
}
},
});