From 92f3920b76cfdd43e7f7e845dc2a515b237fd311 Mon Sep 17 00:00:00 2001 From: Maximiliano forlenza Date: Tue, 29 Aug 2023 17:04:15 -0300 Subject: [PATCH] fix(buildYupSchema): change currency to number --- package.json | 2 +- src/components/Currency/Currency.js | 2 +- src/utils/buildYupSchema.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 47e9c48..251973f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@indec/form-builder", - "version": "2.4.1", + "version": "2.4.3", "description": "Form builder", "main": "index.js", "private": false, diff --git a/src/components/Currency/Currency.js b/src/components/Currency/Currency.js index 0470186..e219d45 100644 --- a/src/components/Currency/Currency.js +++ b/src/components/Currency/Currency.js @@ -7,7 +7,7 @@ import TextField from '../TextField'; function Currency({form, field, label, ...props}) { const handleChange = values => { const {floatValue} = values; - form.setFieldValue(field.name, floatValue); + form.setFieldValue(field.name, typeof floatValue === 'number' ? floatValue : ''); form.setFieldTouched(field.name, false); }; diff --git a/src/utils/buildYupSchema.js b/src/utils/buildYupSchema.js index 14ad64a..9554b5e 100644 --- a/src/utils/buildYupSchema.js +++ b/src/utils/buildYupSchema.js @@ -11,8 +11,8 @@ const getValidatorType = (type, options, metadata) => { case questionTypes.TEXT_FIELD: case questionTypes.DROPDOWN: case questionTypes.RADIO: - case questionTypes.CURRENCY: return Yup.string().default(''); + case questionTypes.CURRENCY: case questionTypes.NUMERIC_FIELD: return Yup.number() .transform(value => (Number.isNaN(value) || value === null || value === undefined || value === '' ? 0 : value));