Skip to content

Commit

Permalink
Merge pull request #211 from onebeyond/fix-dependent-question-for-mul…
Browse files Browse the repository at this point in the history
…tiple-checkboxes

Fix/Shows dependent questions of multiple_checkboxes fields
  • Loading branch information
inigomarquinez committed Mar 12, 2024
2 parents a08bd75 + 787b6c0 commit 98dfeb6
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 9 deletions.
349 changes: 349 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion example/src/forms/Contact/forms.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,25 @@
"disableOthers": true
}
]
}
},
"dependentQuestions": [
{
"condition": "others",
"question": {
"name": "test",
"type": "input",
"label": "Confirm password",
"placeholder": "Confirm password",
"errorMessages": {
"required": "This field is required",
"doesNotMatch": "The passwords do not match"
},
"registerConfig": {
"required": true
}
}
}
]
},
{
"name": "age",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onebeyond/react-form-builder",
"version": "1.5.0",
"version": "1.5.1",
"description": "React from builder using json schema",
"author": "One Beyond",
"license": "MIT",
Expand Down
7 changes: 4 additions & 3 deletions src/Questions/MultipleCheckboxes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ const disableOthers = (e) => {
})
}

const QuestionMultipleCheckboxes = ({ component, form, question, useForm }) => {
const QuestionMultipleCheckboxes = ({ question, useForm }) => {
const {
formState: { errors },
getValues,
register
} = useForm

return (
<div
sx={{
Expand Down Expand Up @@ -70,7 +71,7 @@ const QuestionMultipleCheckboxes = ({ component, form, question, useForm }) => {
}}
>
<Checkbox
data-testid='question-singleCheckbox'
data-testid="question-singleCheckbox"
id={option.name}
aria-describedby={'error_message_' + question.name}
name={question.name}
Expand All @@ -80,6 +81,7 @@ const QuestionMultipleCheckboxes = ({ component, form, question, useForm }) => {
)}
{...register(question.name, {
...question.registerConfig,
onChange: option.disableOthers && disableOthers,
validate: {
minimumLen: question.registerConfig.minimumLen
? () =>
Expand All @@ -95,7 +97,6 @@ const QuestionMultipleCheckboxes = ({ component, form, question, useForm }) => {
: () => true
}
})}
onChange={option.disableOthers && disableOthers}
/>
{option.src ? (
<img src={option.src} />
Expand Down
1 change: 0 additions & 1 deletion src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ const FormBuilder = ({
<QuestionMultipleCheckboxes
useForm={useFormObj}
question={question}
form={form}
/>
{question.dependentQuestions &&
question.dependentQuestions.map(
Expand Down

0 comments on commit 98dfeb6

Please sign in to comment.