From dbe02ac106cc9702e838213436cd7e5367902005 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Mon, 9 May 2011 17:19:23 +0200 Subject: [PATCH] [FIX] Fixed float field bzr revid: fme@openerp.com-20110509151923-vhobe1n1h0495f8t --- addons/base/static/src/js/form.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index 27beadbdecf..fbe9e054365 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -659,15 +659,25 @@ openerp.base.form.FieldUrl = openerp.base.form.FieldChar.extend({ openerp.base.form.FieldFloat = openerp.base.form.FieldChar.extend({ init: function(view, node) { this._super(view, node); - this.validation_regex = /^\d+(\.\d+)?$/; + this.validation_regex = /^-?\d+(\.\d+)?$/; }, set_value: function(value) { - this._super.apply(this, arguments); - var show_value = (value != null && value !== false) ? value.toFixed(2) : ''; + if (!value) { + // As in GTK client, floats default to 0 + value = 0; + } + this._super.apply(this, [value]); + var show_value = value.toFixed(2); this.$element.find('input').val(show_value); }, set_value_from_ui: function() { this.value = this.$element.find('input').val().replace(/,/g, '.'); + }, + validate: function() { + this._super.apply(this, arguments); + if (!this.invalid) { + this.value = Number(this.value); + } } });