Update Member Import
This commit is contained in:
@@ -67,3 +67,49 @@ export function RHFMultiCheckbox({ name, options, ...other }: RHFMultiCheckboxPr
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
interface optionsCustomInterface {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
interface RHFCustomMultiCheckboxProps {
|
||||
name: string;
|
||||
options: optionsCustomInterface[];
|
||||
}
|
||||
|
||||
export function RHFCustomMultiCheckbox({ name, options, ...other }: RHFCustomMultiCheckboxProps) {
|
||||
const { control } = useFormContext();
|
||||
|
||||
return (
|
||||
<Controller
|
||||
name={name}
|
||||
control={control}
|
||||
render={({ field }) => {
|
||||
const onSelected = (option: optionsCustomInterface) =>
|
||||
field.value.includes(option.value)
|
||||
? field.value.filter((value: string) => value !== option.value)
|
||||
: [...field.value, option.value];
|
||||
|
||||
return (
|
||||
<FormGroup>
|
||||
{options.map((option, index) => (
|
||||
<FormControlLabel
|
||||
key={index}
|
||||
control={
|
||||
<Checkbox
|
||||
checked={field.value.includes(option.value)}
|
||||
onChange={() => field.onChange(onSelected(option))}
|
||||
/>
|
||||
}
|
||||
label={option.label}
|
||||
{...other}
|
||||
/>
|
||||
))}
|
||||
</FormGroup>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user