Skip to content

Commit 07bffbd

Browse files
committed
#1287: Fixed error messages
1 parent ff45ea2 commit 07bffbd

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/frontend/src/components/NERFormModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const NERFormModal = ({
4545
disabled={disabled}
4646
showCloseButton={showCloseButton}
4747
>
48-
<form id={formId} onSubmit={handleUseFormSubmit(onSubmitWrapper)}>
48+
<form id={formId} onSubmit={handleUseFormSubmit(onSubmitWrapper)} noValidate>
4949
{children}
5050
</form>
5151
</NERModal>

src/frontend/src/pages/AdminToolsPage/FinanceConfig/AccountCodeFormModal.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { ExpenseType } from 'shared';
22
import { ExpenseTypePayload } from '../../../hooks/finance.hooks';
33
import { Controller, useForm } from 'react-hook-form';
44
import NERFormModal from '../../../components/NERFormModal';
5-
import { Checkbox, FormControl, FormLabel } from '@mui/material';
5+
import { Checkbox, FormControl, FormLabel, FormHelperText } from '@mui/material';
66
import ReactHookTextField from '../../../components/ReactHookTextField';
77
import { useToast } from '../../../hooks/toasts.hooks';
88
import * as yup from 'yup';
99
import { yupResolver } from '@hookform/resolvers/yup';
1010

1111
const schema = yup.object().shape({
12-
code: yup.number().required('Account Code is Required'),
12+
code: yup.number().typeError('Account Code must be a number').required('Account Code is Required'),
1313
name: yup.string().required('Account Name is Required'),
1414
allowed: yup.boolean().required('Allowed is Required')
1515
});
@@ -23,8 +23,12 @@ interface AccountCodeFormModalProps {
2323

2424
const AccountCodeFormModal = ({ showModal, handleClose, defaultValues, onSubmit }: AccountCodeFormModalProps) => {
2525
const toast = useToast();
26-
const { handleSubmit, control, reset } = useForm({
27-
mode: 'onChange',
26+
const {
27+
handleSubmit,
28+
control,
29+
reset,
30+
formState: { errors }
31+
} = useForm({
2832
resolver: yupResolver(schema),
2933
defaultValues: {
3034
code: defaultValues?.code,
@@ -58,10 +62,12 @@ const AccountCodeFormModal = ({ showModal, handleClose, defaultValues, onSubmit
5862
<FormControl fullWidth>
5963
<FormLabel>Account Name</FormLabel>
6064
<ReactHookTextField name="name" control={control} fullWidth />
65+
<FormHelperText error>{errors.name?.message}</FormHelperText>
6166
</FormControl>
6267
<FormControl fullWidth>
6368
<FormLabel>Account Code</FormLabel>
6469
<ReactHookTextField name="code" control={control} fullWidth />
70+
<FormHelperText error>{errors.code?.message}</FormHelperText>
6571
</FormControl>
6672
<FormControl>
6773
<FormLabel>Allowed?</FormLabel>

src/frontend/src/pages/AdminToolsPage/FinanceConfig/CreateVendorModal.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useForm } from 'react-hook-form';
22
import NERFormModal from '../../../components/NERFormModal';
3-
import { FormControl, FormLabel } from '@mui/material';
3+
import { FormControl, FormLabel, FormHelperText } from '@mui/material';
44
import ReactHookTextField from '../../../components/ReactHookTextField';
55
import { useCreateVendor } from '../../../hooks/finance.hooks';
66
import { useToast } from '../../../hooks/toasts.hooks';
@@ -33,8 +33,12 @@ const CreateVendorModal = ({ showModal, handleClose }: NewVendorProps) => {
3333
handleClose();
3434
};
3535

36-
const { handleSubmit, control, reset } = useForm({
37-
mode: 'onChange',
36+
const {
37+
handleSubmit,
38+
control,
39+
reset,
40+
formState: { errors }
41+
} = useForm({
3842
resolver: yupResolver(schema),
3943
defaultValues: {
4044
name: ''
@@ -58,6 +62,7 @@ const CreateVendorModal = ({ showModal, handleClose }: NewVendorProps) => {
5862
<FormControl>
5963
<FormLabel>Vendor Name</FormLabel>
6064
<ReactHookTextField name="name" control={control} sx={{ width: 1 }} />
65+
<FormHelperText error>{errors.name?.message}</FormHelperText>
6166
</FormControl>
6267
</NERFormModal>
6368
);

0 commit comments

Comments
 (0)