Pulling data from supabase, using <Controller /> with a column that's an array?
Hello, I have the following setup:
questionData.choices is an array of strings. I have:
But something tells me this isn't going to update each question choice appropriately.
import { useForm } from "@refinedev/react-hook-form";
const {
saveButtonProps,
refineCore: { query, formLoading, onFinish },
handleSubmit,
register,
control,
formState: { errors }
} = useForm<Selection>({
refineCoreProps: {
meta: {
select: "*, category_id(*), exam(*), exam_section(*)",
},
},
});
const questionData = query?.data?.data;import { useForm } from "@refinedev/react-hook-form";
const {
saveButtonProps,
refineCore: { query, formLoading, onFinish },
handleSubmit,
register,
control,
formState: { errors }
} = useForm<Selection>({
refineCoreProps: {
meta: {
select: "*, category_id(*), exam(*), exam_section(*)",
},
},
});
const questionData = query?.data?.data;questionData.choices is an array of strings. I have:
<FormGroup>
{questionData?.choices.map((choice: string, index: number) => (
<TextField
key={index}
{...register(`choices.[${index}]`, {
required: "This field is required",
})}
defaultValue={choice}
error={!!(errors as any)?.choices?.[index]}
helperText={(errors as any)?.choices?.[index]?.message}
margin="normal"
fullWidth
slotProps={{ inputLabel: { shrink: true } }}
type="text"
label={`Choice ${index + 1}`}
name={`choices.[${index}]`}
/>
))}
</FormGroup><FormGroup>
{questionData?.choices.map((choice: string, index: number) => (
<TextField
key={index}
{...register(`choices.[${index}]`, {
required: "This field is required",
})}
defaultValue={choice}
error={!!(errors as any)?.choices?.[index]}
helperText={(errors as any)?.choices?.[index]?.message}
margin="normal"
fullWidth
slotProps={{ inputLabel: { shrink: true } }}
type="text"
label={`Choice ${index + 1}`}
name={`choices.[${index}]`}
/>
))}
</FormGroup>But something tells me this isn't going to update each question choice appropriately.
