diff --git a/src/components/forms/validator.js b/src/components/forms/validator.js index f807840c..8637f158 100644 --- a/src/components/forms/validator.js +++ b/src/components/forms/validator.js @@ -8,6 +8,14 @@ export const required = (value: Field) => (value ? undefined : 'Required') export const mustBeNumber = (value: number) => (Number.isNaN(Number(value)) ? 'Must be a number' : undefined) +export const greaterThan = (min: number) => (value: string) => { + if (Number.isNaN(Number(value)) || Number.parseFloat(value) > Number(min)) { + return undefined + } + + return `Should be greater than ${min}` +} + export const minValue = (min: number) => (value: string) => { if (Number.isNaN(Number(value)) || Number.parseInt(value, 10) >= Number(min)) { return undefined diff --git a/src/routes/open/components/SafeForm/DailyLimit/index.jsx b/src/routes/open/components/SafeForm/DailyLimit/index.jsx index cad36dbf..83c4ff6b 100644 --- a/src/routes/open/components/SafeForm/DailyLimit/index.jsx +++ b/src/routes/open/components/SafeForm/DailyLimit/index.jsx @@ -2,7 +2,7 @@ import * as React from 'react' import Field from '~/components/forms/Field' import TextField from '~/components/forms/TextField' -import { composeValidators, mustBeNumber, required, minValue } from '~/components/forms/validator' +import { composeValidators, mustBeNumber, required, greaterThan } from '~/components/forms/validator' import Block from '~/components/layout/Block' import { FIELD_DAILY_LIMIT } from '~/routes/open/components/fields' @@ -12,7 +12,7 @@ const DailyLimit = () => ( name={FIELD_DAILY_LIMIT} component={TextField} type="text" - validate={composeValidators(required, mustBeNumber, minValue(1))} + validate={composeValidators(required, mustBeNumber, greaterThan(0))} placeholder="Daily Limit*" text="Daily Limit" />