Skip to content

Commit

Permalink
feat: add dependant questions logic to radio buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloelisseo committed Feb 16, 2024
1 parent acdaf17 commit e81e81b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
55 changes: 54 additions & 1 deletion example/src/forms.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,23 @@
"value": "no"
}
]
}
},
"dependentQuestions": [
{
"condition": "yes",
"question": {
"name": "checkbox_with_link",
"type": "checkbox",
"label": "External [link](https://www.google.com)",
"errorMessages": {
"required": "This field is required"
},
"registerConfig": {
"required": true
}
}
}
]
},
{
"name": "checkbox_with_link",
Expand All @@ -276,6 +292,43 @@
"registerConfig": {
"required": true
}
},
{
"name": "radio_with_dependent_question",
"type": "radio",
"label": "Radio with dependent question",
"options": [
{
"label": "Yes",
"value": "yes"
},
{
"label": "No",
"value": "no"
}
],
"dependentQuestions": [
{
"condition": "yes",
"question": {
"name": "checkbox_with_link",
"type": "checkbox",
"label": "External [link](https://www.google.com)",
"errorMessages": {
"required": "This field is required"
},
"registerConfig": {
"required": true
}
}
}
],
"errorMessages": {
"required": "This field is required"
},
"registerConfig": {
"required": true
}
}
],
"callForAction": [
Expand Down
16 changes: 11 additions & 5 deletions src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,17 @@ const FormBuilder = ({
<QuestionStatic useForm={useFormObj} question={question} form={form} />
),
radio: (
<QuestionRadio
useForm={useFormObj}
question={question}
onLinkOpen={onLinkOpen}
/>
<>
<QuestionRadio
useForm={useFormObj}
question={question}
onLinkOpen={onLinkOpen}
/>
{question.dependentQuestions &&
question.dependentQuestions.map(
ConditionalQuestion(question.dependentQuestions, question.name)
)}
</>
),
date: (
<QuestionDate
Expand Down

0 comments on commit e81e81b

Please sign in to comment.