From 4620ff3c00a7b66346f3a7d095223415596da0d9 Mon Sep 17 00:00:00 2001 From: Alyssa Wang Date: Wed, 15 Jan 2025 18:00:38 -0500 Subject: [PATCH] add check for locked input in checkbox group (#590) --- .../InputsModal/InputCheckboxGroup.tsx | 2 +- .../dev_demo_ig_stu1/groups/demo_group.rb | 24 +++++++++++++++++++ .../utils/preset_template_generator_spec.rb | 9 +++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/client/src/components/InputsModal/InputCheckboxGroup.tsx b/client/src/components/InputsModal/InputCheckboxGroup.tsx index 13fab7688..02b8c73cd 100644 --- a/client/src/components/InputsModal/InputCheckboxGroup.tsx +++ b/client/src/components/InputsModal/InputCheckboxGroup.tsx @@ -120,7 +120,7 @@ const InputCheckboxGroup: FC = ({ size="small" color="secondary" name={option.value} - disabled={!!option.locked} + disabled={input.locked || !!option.locked} checked={values[option.value as keyof CheckboxValues] || false} onBlur={(e) => { if (e.currentTarget === e.target) { diff --git a/dev_suites/dev_demo_ig_stu1/groups/demo_group.rb b/dev_suites/dev_demo_ig_stu1/groups/demo_group.rb index 26a98f849..ddf49b1f9 100644 --- a/dev_suites/dev_demo_ig_stu1/groups/demo_group.rb +++ b/dev_suites/dev_demo_ig_stu1/groups/demo_group.rb @@ -317,6 +317,7 @@ class DemoGroup < Inferno::TestGroup description: 'Checkbox description', default: ['value2'], optional: false, + locked: true, options: { list_options: [ { @@ -333,6 +334,29 @@ class DemoGroup < Inferno::TestGroup run { info "Received the following 'checkbox' variable: '#{locked_checkbox_group}'" } end + test 'locked single checkbox in checkbox group input' do + input :locked_single_checkbox_group, + title: 'Locked Single Checkbox in Group Input Example', + type: 'checkbox', + description: 'Checkbox description', + default: ['value2'], + optional: false, + options: { + list_options: [ + { + label: 'Label 1', + value: 'value1' + }, { + label: 'Label 2', + value: 'value2', + locked: true + } + ] + } + + run { info "Received the following 'checkbox' variable: '#{locked_single_checkbox_group}'" } + end + test 'single checkbox input' do input :single_checkbox, title: 'Single Checkbox Input Example', diff --git a/spec/inferno/utils/preset_template_generator_spec.rb b/spec/inferno/utils/preset_template_generator_spec.rb index fec7a8cfc..f52e6bb27 100644 --- a/spec/inferno/utils/preset_template_generator_spec.rb +++ b/spec/inferno/utils/preset_template_generator_spec.rb @@ -43,6 +43,15 @@ _title: 'Locked Checkbox Group Input Example', _description: 'Checkbox description', _optional: false, + _locked: true, + _options: { list_options: [{ label: 'Label 1', value: 'value1' }, + { label: 'Label 2', locked: true, value: 'value2' }] }, + value: ['value2'] }, + { name: 'locked_single_checkbox_group', + _type: 'checkbox', + _title: 'Locked Single Checkbox in Group Input Example', + _description: 'Checkbox description', + _optional: false, _options: { list_options: [{ label: 'Label 1', value: 'value1' }, { label: 'Label 2', locked: true, value: 'value2' }] }, value: ['value2'] },