From e81e81b2dee69e884ae9344af9f0092e0792263f Mon Sep 17 00:00:00 2001 From: pabloelisseo Date: Fri, 16 Feb 2024 09:32:09 +0100 Subject: [PATCH] feat: add dependant questions logic to radio buttons --- example/src/forms.json | 55 +++++++++++++++++++++++++++++++++++++++++- src/builder.js | 16 ++++++++---- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/example/src/forms.json b/example/src/forms.json index cdf7b353..55a246d9 100644 --- a/example/src/forms.json +++ b/example/src/forms.json @@ -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", @@ -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": [ diff --git a/src/builder.js b/src/builder.js index d65b7bc9..c31537bd 100644 --- a/src/builder.js +++ b/src/builder.js @@ -167,11 +167,17 @@ const FormBuilder = ({ ), radio: ( - + <> + + {question.dependentQuestions && + question.dependentQuestions.map( + ConditionalQuestion(question.dependentQuestions, question.name) + )} + ), date: (