I’m using React, MUI and Formik.
I have a table and how do I allow that only one radio
would be selected by row?
This is my codesandbox: CLICK HERE
import { TableCell, TableRow, TextField, Radio } from "@mui/material";
import { FastField } from "formik";
const CustomTableRow = ({ row, index }) => {
return (
<TableRow
key={row.id}
sx={{
"&:last-child td, &:last-child th": { border: 0 },
}}
>
<TableCell component="th" scope="row">
<FastField
name={`rows.${index}.attribute`}
component={CustomTextField}
fullWidth
/>
</TableCell>
<TableCell>
<FastField
checked={`rows.${index}.radio1`}
name={`rows.${index}.radio1`}
component={Radio}
fullWidth
/>
</TableCell>
<TableCell colSpan={1}>
<FastField
checked={`rows.${index}.radio2`}
name={`rows.${index}.radio2`}
component={Radio}
fullWidth
/>
</TableCell>
</TableRow>
);
};
CustomTableRow.displayName = "CustomTableRow";
export default CustomTableRow;