From 19eef5d658d46719665635e28883be755f395813 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 20 Apr 2017 12:16:51 +0200 Subject: [FIX] web: allow virtual ids for integer fields Before this change, the redering throw an exception when we try to open a form view with a virtual id. eg: recurrent event in calendar --- addons/web/static/src/js/fields/basic_fields.js | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 5a3bd699a7c..344f7174c54 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -482,6 +482,7 @@ var FieldMonetary = InputField.extend({ * @override * @private * @param {float} value + * @returns {string} */ _formatValue: function (value) { var format = field_utils.format[this.mode === 'edit' ? "float" : "monetary"]; @@ -598,6 +599,10 @@ var FieldBoolean = AbstractField.extend({ var FieldInteger = InputField.extend({ supportedFieldTypes: ['integer'], + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + /** * For integer fields, 0 is a valid value. * @@ -606,6 +611,34 @@ var FieldInteger = InputField.extend({ isSet: function () { return this.value === 0 || this._super.apply(this, arguments); }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Format integer value + * + * Note: We have to overwrite this method to allow virtual ids. A virtual id + * is a character string composed of an integer and has a dash and other + * information. + * E.g: in calendar, the recursive event have virtual id linked to a real id + * virtual event id "23-20170418020000" is linked to the event id 23 + * + * @override + * @private + * @param {integer|string} value + * @returns {string} + */ + _formatValue: function (value) { + if (typeof value === 'string') { + if (!/^[0-9]+-/.test(value)) { + throw new Error('"' + value + '" is not an integer or a virtual id'); + } + return value; + } + return field_utils.format.integer(value, this.field); + }, }); var FieldFloat = InputField.extend({ -- cgit v1.2.3