diff options
| author | Christophe Matthieu <chm@odoo.com> | 2017-04-20 12:16:51 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2017-04-20 17:07:37 +0200 |
| commit | 19eef5d658d46719665635e28883be755f395813 (patch) | |
| tree | 0855cb07fd9484293cb8e2d1e320211212f4eec5 /addons/web/static/src/js/fields/basic_fields.js | |
| parent | 86af036ea1175f4a9a5fbca806ab49665fdbc4b0 (diff) | |
[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
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 33 |
1 files changed, 33 insertions, 0 deletions
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({ |
