From 1916543d6ba0ba4a5fc5b7d4016728645c68eb9c Mon Sep 17 00:00:00 2001 From: Tibor Postek Date: Wed, 5 Feb 2020 13:26:24 +0100 Subject: [PATCH] #2 fix validation of select component --- js/components/projects/projectModal/index.js | 54 ++++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/js/components/projects/projectModal/index.js b/js/components/projects/projectModal/index.js index 99a66005d..7dea31c0e 100644 --- a/js/components/projects/projectModal/index.js +++ b/js/components/projects/projectModal/index.js @@ -2,7 +2,17 @@ import React, { memo } from 'react'; import Modal from '../../common/Modal'; import { useDispatch, useSelector } from 'react-redux'; import { resetProjectState, setProjectModalOpen } from '../redux/actions'; -import { makeStyles, RadioGroup, Radio, Grid, Typography, MenuItem } from '@material-ui/core'; +import { + makeStyles, + RadioGroup, + Radio, + Grid, + Typography, + MenuItem, + InputLabel, + FormControl, + FormHelperText +} from '@material-ui/core'; import { Title, Description, Label, Link } from '@material-ui/icons'; import { Autocomplete } from '@material-ui/lab'; import { DJANGO_CONTEXT } from '../../../utils/djangoContext'; @@ -25,7 +35,8 @@ const useStyles = makeStyles(theme => ({ margin: theme.spacing(1) }, formControl: { - margin: theme.spacing(3) + margin: theme.spacing(1), + width: 400 } })); @@ -55,7 +66,7 @@ export const ProjectModal = memo(({}) => { initialValues={{ title: '', description: '', - target: '', + selectedTarget: '', tags: [] }} validate={values => { @@ -66,19 +77,19 @@ export const ProjectModal = memo(({}) => { if (!values.description) { errors.description = 'Required'; } - if (!values.target) { - errors.target = 'Required'; + if (values.selectedTarget === '') { + errors.selectedTarget = 'Required'; } + console.log(errors); return errors; }} onSubmit={(values, { setSubmitting }) => { const data = {}; data.username = DJANGO_CONTEXT['username']; - console.log(values); setSubmitting(false); }} > - {({ submitForm, isSubmitting }) => ( + {({ submitForm, isSubmitting, errors }) => (
@@ -98,26 +109,37 @@ export const ProjectModal = memo(({}) => { } - field={} + field={} /> } - field={} + field={} /> } field={ - + + + Target + + + {errors.selectedTarget} + } />