From 76a84aa23e1690c1f32af2fd67d52202e92c221c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 16 May 2018 23:45:18 +0200 Subject: [PATCH] Format correctly numbers in Dict widgets - display 0 instead of empty - round to the number of digits issue7429 review50341002 --- src/view/form.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/view/form.js b/src/view/form.js index 788c104aed..8b62288db6 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -4343,18 +4343,44 @@ function eval_pyson(value){ return null; } return value; - } + }, + set_value: function(value) { + if (value !== null) { + this.input.val(value); + } else { + this.input.val(''); + } + }, }); Sao.View.Form.Dict.Float = Sao.class_(Sao.View.Form.Dict.Integer, { class_: 'dict-float', + digits: function() { + var default_ = [16, 2]; + var record = this.parent_widget.record(); + if (!record) { + return default_; + } + var digits = record.expr_eval(this.definition.digits || default_); + digits.forEach(function(v, i, digits) { + if (v === null) { + digits[i] = default_[i]; + } + }); + return digits; + }, get_value: function() { var value = Number(this.input.val()); if (isNaN(value)) { return null; } return value; - } + }, + set_value: function(value) { + var digits = this.digits(); + value = value.toFixed(digits[1]); + Sao.View.Form.Dict.Float._super.set_value.call(this, value); + }, }); Sao.View.Form.Dict.Numeric = Sao.class_(Sao.View.Form.Dict.Float, {