From 8d8121844c98762ea836e1994f3f374835a9249d Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Thu, 23 Apr 2020 15:28:09 +0200 Subject: [PATCH] =?UTF-8?q?:bug:=20corrige=20la=20page=20blanche=20lors=20?= =?UTF-8?q?de=20l'=C3=A9criture=20de=20nombre=20avec=20virgule=20dans=20ar?= =?UTF-8?q?tiste=20auteur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CurrencyInput/CurrencyInput.test.js | 25 +++++++++++++++++++ .../CurrencyInput/CurrencyInput.tsx | 2 +- source/locales/rules-en.yaml | 8 +++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/source/components/CurrencyInput/CurrencyInput.test.js b/source/components/CurrencyInput/CurrencyInput.test.js index da6ed33ea..078721ef4 100644 --- a/source/components/CurrencyInput/CurrencyInput.test.js +++ b/source/components/CurrencyInput/CurrencyInput.test.js @@ -145,4 +145,29 @@ describe('CurrencyInput', () => { wrapper.setProps({ value: '1000000' }) expect(Number(getInlineWidth().replace(/em$/, ''))).to.be.greaterThan(5) }) + + it('should not call onChange if the value is not a correct number', () => { + let onChange = spy() + mount() + .find('input') + .simulate('change', { + target: { value: '-', focus: () => {} } + }) + mount() + .find('input') + .simulate('change', { + target: { value: '.', focus: () => {} } + }) + mount() + .find('input') + .simulate('change', { + target: { value: '.5', focus: () => {} } + }) + mount() + .find('input') + .simulate('change', { + target: { value: '8.', focus: () => {} } + }) + expect(onChange).not.to.have.been.called + }) }) diff --git a/source/components/CurrencyInput/CurrencyInput.tsx b/source/components/CurrencyInput/CurrencyInput.tsx index 6442a8cc2..58b8d1f4a 100644 --- a/source/components/CurrencyInput/CurrencyInput.tsx +++ b/source/components/CurrencyInput/CurrencyInput.tsx @@ -49,7 +49,7 @@ export default function CurrencyInput({ // Only trigger the `onChange` event if the value has changed -- and not // only its formating, we don't want to call it when a dot is added in `12.` // for instance - if (!nextValue.current) { + if (!nextValue.current || nextValue.current.match(/(\.$)|(^\.)|(-$)/)) { return } event.persist() diff --git a/source/locales/rules-en.yaml b/source/locales/rules-en.yaml index e50eb5689..aa7254bc7 100644 --- a/source/locales/rules-en.yaml +++ b/source/locales/rules-en.yaml @@ -1042,11 +1042,11 @@ contrat salarié . activité partielle . heures chômées: titre.fr: heures chômées contrat salarié . activité partielle . heures travaillées: contrôles.0.en: >- - [automatic] In the case of part-time work, the working time must be less - than that stipulated in the employment contract. + [automatic] In the context of the partial activity, the working time must be + less than that stipulated in the employment contract. contrôles.0.fr: >- - Dans le cadre du temps partiel, le temps de travail doit être inférieur à - celui inscrit dans le contrat de travail. + Dans le cadre de l'activité partielle, le temps de travail doit être + inférieur à celui inscrit dans le contrat de travail. description.en: >- [automatic] In the case of short-time working, the number of hours remaining worked. Must be less than the contractual time.