From 52b81a27fb54e8db4e13fb3e4e5f4cb3cd7048cf Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Thu, 13 Dec 2018 15:26:47 +0300 Subject: [PATCH] Send lease duration as number --- client/src/components/Settings/Dhcp/Form.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/src/components/Settings/Dhcp/Form.js b/client/src/components/Settings/Dhcp/Form.js index a4caea0b..e65ab04a 100644 --- a/client/src/components/Settings/Dhcp/Form.js +++ b/client/src/components/Settings/Dhcp/Form.js @@ -4,7 +4,7 @@ import { Field, reduxForm } from 'redux-form'; import { R_IPV4 } from '../../../helpers/constants'; const required = (value) => { - if (value) { + if (value || value === 0) { return false; } return 'Required field'; @@ -17,6 +17,15 @@ const ipv4 = (value) => { return false; }; +const isPositive = (value) => { + if ((value || value === 0) && (value <= 0)) { + return 'Must be greater than 0'; + } + return false; +}; + +const toNumber = value => value && parseInt(value, 10); + const renderField = ({ input, className, placeholder, type, disabled, meta: { touched, error }, }) => ( @@ -104,8 +113,9 @@ const Form = (props) => { type="number" className="form-control" placeholder="Lease duration" - validate={[required]} + validate={[required, isPositive]} disabled={!enabled} + normalize={toNumber} />