form bugfixes

- validation message
- cancel
This commit is contained in:
cv
2021-03-23 13:37:07 +01:00
parent fa9553a279
commit 3a9daec61e
3 changed files with 13 additions and 20 deletions
+2 -7
View File
@@ -10,13 +10,8 @@ export default function ChakraInput(props) {
<Field name={name}>
{({ field, form }) => {
return (
<FormControl>
<FormLabel
htmlFor={name}
isInvalid={form.errors[name] && form.touched[name]}
>
{label}
</FormLabel>
<FormControl isInvalid={form.errors[name] && form.touched[name]}>
<FormLabel htmlFor={name}>{label}</FormLabel>
<Input id={name} {...rest} {...field} />
<FormErrorMessage>{form.errors[name]}</FormErrorMessage>
</FormControl>
+2 -7
View File
@@ -15,13 +15,8 @@ export default function ChakraNumberInput(props) {
<Field name={name}>
{({ field, form }) => {
return (
<FormControl>
<FormLabel
htmlFor={name}
isInvalid={form.errors[name] && form.touched[name]}
>
{label}
</FormLabel>
<FormControl isInvalid={form.errors[name] && form.touched[name]}>
<FormLabel htmlFor={name}>{label}</FormLabel>
<NumberInput
defaultValue={field.value}
{...rest}
+9 -6
View File
@@ -1,5 +1,5 @@
import { Button } from '@chakra-ui/button';
import { Formik } from 'formik';
import { Form, Formik } from 'formik';
import * as Yup from 'yup';
import ChakraInput from '../../common/input/ChakraInput';
import ChakraNumberInput from '../../common/input/ChakraNumberInput';
@@ -23,10 +23,13 @@ export default function EventForm(props) {
};
const validationSchema = Yup.object({
title: Yup.string().required(),
title: Yup.string().required('An event requires a title'),
subtitle: Yup.string(),
presenter: Yup.string(),
timerDuration: Yup.number().required().min(1).max(60),
timerDuration: Yup.number()
.min(1)
.max(60)
.required('An event requires a duration'),
});
const submitForm = (values) => {
@@ -50,7 +53,7 @@ export default function EventForm(props) {
}}
>
{(props) => (
<form onSubmit={props.handleSubmit}>
<Form onSubmit={props.handleSubmit}>
<ChakraInput name='title' label='Event Title' />
<ChakraInput name='subtitle' label='Event Subtitle' />
<ChakraInput name='presenter' label='Presenter Name' />
@@ -67,7 +70,7 @@ export default function EventForm(props) {
<Button
variant='outline'
disabled={props.isSubmitting}
onClick={() => console.log('ccancel form?')}
type='reset'
>
Cancel
</Button>
@@ -80,7 +83,7 @@ export default function EventForm(props) {
Save
</Button>
</div>
</form>
</Form>
)}
</Formik>
</div>