This commit is contained in:
R
2022-09-17 00:51:02 +07:00
parent 300b53942d
commit a9f29cd19d
28 changed files with 1122 additions and 13 deletions

View File

@@ -0,0 +1,41 @@
import { Autocomplete, TextField, TextFieldProps } from '@mui/material';
import { useState } from 'react';
import { Controller, useFormContext } from 'react-hook-form';
interface IProps {
options: any[];
name: string;
label?: string;
}
export default function RHFAutocomplete({ name, options, label, ...other }: IProps & TextFieldProps) {
const { control } = useFormContext();
console.log(control)
const [value, setValue] = useState<string | null>(options[0]);
const [inputValue, setInputValue] = useState('');
return (
<Controller
name={name}
control={control}
render={({ field, fieldState: { error } }) => (
<Autocomplete
{...field}
options={options}
value={value}
onChange={(event: any, newValue: string | null) => {
// console.log('fuck', newValue)
setValue(newValue.id);
}}
inputValue={inputValue}
onInputChange={(event, newInputValue) => {
setInputValue(newInputValue);
}}
renderInput={(params) => <TextField {...params} label={label ?? name} />}
{...other}
/>
)}
/>
);
}