Skip to content

Commit 98dfeb6

Browse files
Merge pull request #211 from onebeyond/fix-dependent-question-for-multiple-checkboxes
Fix/Shows dependent questions of multiple_checkboxes fields
2 parents a08bd75 + 787b6c0 commit 98dfeb6

File tree

7 files changed

+376
-9
lines changed

7 files changed

+376
-9
lines changed

CHANGELOG.md

Lines changed: 349 additions & 0 deletions
Large diffs are not rendered by default.

example/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/forms/Contact/forms.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,25 @@
187187
"disableOthers": true
188188
}
189189
]
190-
}
190+
},
191+
"dependentQuestions": [
192+
{
193+
"condition": "others",
194+
"question": {
195+
"name": "test",
196+
"type": "input",
197+
"label": "Confirm password",
198+
"placeholder": "Confirm password",
199+
"errorMessages": {
200+
"required": "This field is required",
201+
"doesNotMatch": "The passwords do not match"
202+
},
203+
"registerConfig": {
204+
"required": true
205+
}
206+
}
207+
}
208+
]
191209
},
192210
{
193211
"name": "age",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onebeyond/react-form-builder",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "React from builder using json schema",
55
"author": "One Beyond",
66
"license": "MIT",

src/Questions/MultipleCheckboxes/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ const disableOthers = (e) => {
2626
})
2727
}
2828

29-
const QuestionMultipleCheckboxes = ({ component, form, question, useForm }) => {
29+
const QuestionMultipleCheckboxes = ({ question, useForm }) => {
3030
const {
3131
formState: { errors },
3232
getValues,
3333
register
3434
} = useForm
35+
3536
return (
3637
<div
3738
sx={{
@@ -70,7 +71,7 @@ const QuestionMultipleCheckboxes = ({ component, form, question, useForm }) => {
7071
}}
7172
>
7273
<Checkbox
73-
data-testid='question-singleCheckbox'
74+
data-testid="question-singleCheckbox"
7475
id={option.name}
7576
aria-describedby={'error_message_' + question.name}
7677
name={question.name}
@@ -80,6 +81,7 @@ const QuestionMultipleCheckboxes = ({ component, form, question, useForm }) => {
8081
)}
8182
{...register(question.name, {
8283
...question.registerConfig,
84+
onChange: option.disableOthers && disableOthers,
8385
validate: {
8486
minimumLen: question.registerConfig.minimumLen
8587
? () =>
@@ -95,7 +97,6 @@ const QuestionMultipleCheckboxes = ({ component, form, question, useForm }) => {
9597
: () => true
9698
}
9799
})}
98-
onChange={option.disableOthers && disableOthers}
99100
/>
100101
{option.src ? (
101102
<img src={option.src} />

src/builder.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ const FormBuilder = ({
213213
<QuestionMultipleCheckboxes
214214
useForm={useFormObj}
215215
question={question}
216-
form={form}
217216
/>
218217
{question.dependentQuestions &&
219218
question.dependentQuestions.map(

0 commit comments

Comments
 (0)