Skip to content

Commit

Permalink
fix: send option on multicheckbox to disable only when selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus Sabroso committed Jan 24, 2025
1 parent 3e9d5f8 commit b37406e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Questions/MultipleCheckboxes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import Label from '../../Fields/Label'

import ReactMarkdown from 'react-markdown'

const disableOthers = (e) => {
Object.entries(e.target.form).forEach(([, v]) => {
if (e.target.checked === true) {
const disableOthers = (option) => (e) => {
Object.entries(e?.target?.form || []).forEach(([, v]) => {
if (e.target.checked === true && option.value === e.target.value) {
if (v.type === 'checkbox' && v.name === e.target.name && v !== e.target) {
v.checked = false
v.disabled = true
}
e.target.disabled = false
e.target.checked = true
}
if (e.target.checked === false) {
if (e?.target?.checked === false) {
if (v.type === 'checkbox' && v.name === e.target.name) {
v.disabled = false
}
Expand Down Expand Up @@ -71,7 +71,7 @@ const QuestionMultipleCheckboxes = ({ 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 @@ -81,7 +81,7 @@ const QuestionMultipleCheckboxes = ({ question, useForm }) => {
)}
{...register(question.name, {
...question.registerConfig,
onChange: option.disableOthers && disableOthers,
onChange: option.disableOthers && disableOthers(option),
validate: {
minimumLen: question.registerConfig.minimumLen
? () =>
Expand Down

0 comments on commit b37406e

Please sign in to comment.