You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am creating a form where the user can create simple multiple choice questions. The form consists of a question (string), and an array of answer options with a string for the text and a boolean to indicate whether it is a the correct answer. I struggled to get toTypedSchema to work nicely together with the useArrayField function.
I came up with the following working solution but I'm not convinced that this is the right way to it for two reasons:
Typing the useFieldArray generic with NonNullable<typeof values.questionOptions>[number] feels like an anti-pattern.
The array is validated immediately, instead of on blur/touch (like the question variable is).
In addition, I am also struggling to validate that exactly one question is marked as correct. But since I am using radio buttons with a default value set to the first array item it is not that urgent of an issue I guess.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am creating a form where the user can create simple multiple choice questions. The form consists of a question (string), and an array of answer options with a string for the text and a boolean to indicate whether it is a the correct answer. I struggled to get
toTypedSchema
to work nicely together with theuseArrayField
function.I came up with the following working solution but I'm not convinced that this is the right way to it for two reasons:
NonNullable<typeof values.questionOptions>[number]
feels like an anti-pattern.In addition, I am also struggling to validate that exactly one question is marked as correct. But since I am using radio buttons with a default value set to the first array item it is not that urgent of an issue I guess.
Is there a better way to go about this?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions