main
Last change
on this file was 5d6f37a, checked in by Naum Shapkarovski <naumshapkarovski@…>, 7 weeks ago |
add customer
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[5d6f37a] | 1 | import { useFormContext, Controller } from 'react-hook-form';
|
---|
| 2 | // @mui
|
---|
| 3 | import TextField, { TextFieldProps } from '@mui/material/TextField';
|
---|
| 4 |
|
---|
| 5 | // ----------------------------------------------------------------------
|
---|
| 6 |
|
---|
| 7 | type Props = TextFieldProps & {
|
---|
| 8 | name: string;
|
---|
| 9 | };
|
---|
| 10 |
|
---|
| 11 | export default function RHFTextField({ name, helperText, type, ...other }: Props) {
|
---|
| 12 | const { control } = useFormContext();
|
---|
| 13 |
|
---|
| 14 | return (
|
---|
| 15 | <Controller
|
---|
| 16 | name={name}
|
---|
| 17 | control={control}
|
---|
| 18 | render={({ field, fieldState: { error } }) => (
|
---|
| 19 | <TextField
|
---|
| 20 | {...field}
|
---|
| 21 | fullWidth
|
---|
| 22 | type={type}
|
---|
| 23 | value={type === 'number' && field.value === 0 ? '' : field.value}
|
---|
| 24 | onChange={(event) => {
|
---|
| 25 | if (type === 'number') {
|
---|
| 26 | field.onChange(Number(event.target.value));
|
---|
| 27 | } else {
|
---|
| 28 | field.onChange(event.target.value);
|
---|
| 29 | }
|
---|
| 30 | }}
|
---|
| 31 | error={!!error}
|
---|
| 32 | helperText={error ? error?.message : helperText}
|
---|
| 33 | {...other}
|
---|
| 34 | />
|
---|
| 35 | )}
|
---|
| 36 | />
|
---|
| 37 | );
|
---|
| 38 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.