Skip to content

Commit

Permalink
support conditional rendering for survey questions
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdelsordo committed Nov 9, 2023
1 parent 88bf437 commit 3a57459
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const SurveyComponent = ({
}) => {
const navigate = useNavigate();

const { handleSubmit, reset, control, watch } = useForm({
const { handleSubmit, reset, control, watch, getValues } = useForm({
defaultValues: formDefault,
});

Expand Down Expand Up @@ -201,6 +201,13 @@ const SurveyComponent = ({
>
<Stack spacing={formSpacing} mb={formSpacing} mt={formSpacing}>
{surveyStructure?.survey_questions.map((q) => {
if (
q.conditional_on &&
getValues(q.conditional_on.id) !== q.conditional_on.value
) {
return null;
}

switch (q.response_type) {
case "radio":
return (
Expand Down

0 comments on commit 3a57459

Please sign in to comment.