From 18cbe0623f9438bd5b551258069e3893069ba7ea Mon Sep 17 00:00:00 2001 From: Mael Date: Thu, 1 Aug 2019 18:10:22 +0200 Subject: [PATCH] On oublie cette histoire de faux pourcentages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduit au commit précédent, car je n'avais pas vu que l'option format (couplée au normalize) de redux form existait. --- source/components/Value.js | 4 --- .../components/conversation/FormDecorator.js | 17 ++++++++-- source/components/conversation/Input.js | 1 - source/règles/base.yaml | 31 +++++++++---------- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/source/components/Value.js b/source/components/Value.js index a158bdff1..6d21ecdb1 100644 --- a/source/components/Value.js +++ b/source/components/Value.js @@ -80,10 +80,6 @@ export default withLanguage( numberFormatter({ style: 'percent', maximumFractionDigits: 3 })( nodeValue ) - ) : unitText === '(%)' ? ( - numberFormatter({ style: 'percent', maximumFractionDigits: 3 })( - nodeValue / 100 - ) ) : ( <> {numberFormatter({ diff --git a/source/components/conversation/FormDecorator.js b/source/components/conversation/FormDecorator.js index 6afc10a29..87a0555d2 100644 --- a/source/components/conversation/FormDecorator.js +++ b/source/components/conversation/FormDecorator.js @@ -35,12 +35,25 @@ export var FormDecorator = formType => RenderField => helpVisible: false } render() { - let { stepAction, fieldName, inversion, setFormValue } = this.props + let { + stepAction, + fieldName, + inversion, + setFormValue, + unit + } = this.props let submit = cause => stepAction('fold', fieldName, cause), stepProps = { ...this.props, submit, - setFormValue: (value, name = fieldName) => setFormValue(name, value) + setFormValue: (value, name = fieldName) => + setFormValue(name, value), + ...(unit === '%' + ? { + format: x => (x == null ? null : x * 100), + normalize: x => (x == null ? null : x / 100) + } + : {}) } return ( diff --git a/source/components/conversation/Input.js b/source/components/conversation/Input.js index 518535545..be4fd7eb2 100644 --- a/source/components/conversation/Input.js +++ b/source/components/conversation/Input.js @@ -55,7 +55,6 @@ export default compose( /> {suffixed && (