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.