Skip to content

Commit

Permalink
support for dynamic checkboxes (#3181)
Browse files Browse the repository at this point in the history
Add support for checking checkboxes based off of select options.
  • Loading branch information
johrstrom authored Nov 22, 2023
1 parent e5c2116 commit 1f7381a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
18 changes: 15 additions & 3 deletions apps/dashboard/app/javascript/dynamic_forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,21 @@ function setValue(event, changeId) {
const changeVal = table.get(chosenVal, undefined);

if(changeVal !== undefined) {
const innerElement = $(`#${changeId}`);
innerElement.attr('value', changeVal);
innerElement.val(changeVal);
const element = document.getElementById(changeId);
if(element['type'] == 'checkbox') {
setCheckboxValue(element, changeVal);
} else {
element.value = changeVal;
}
}
}

function setCheckboxValue(checkbox, value) {
const positiveValue = checkbox.value;
if(value == positiveValue) {
checkbox.checked = true;
} else {
checkbox.checked = false;
}
}

Expand Down
4 changes: 4 additions & 0 deletions apps/dashboard/test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def find_value(ele, visible: false)
find("##{bc_ele_id(ele)}", visible: visible).value
end

def checked?(ele)
find("##{bc_ele_id(ele)}").checked?
end

def find_css_class(id)
find("##{id}")['class'].to_s
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,13 @@ attributes:
'medium', 'medium',
data-option-for-classroom-astronomy-5678: false,
data-option-for-classroom-astronomy-with/other-characters/8846.31.4: false,
data-set-checkbox-test: 0,
]
- [
'large', 'large',
data-option-for-classroom-astronomy-5678: false,
data-option-for-classroom-astronomy-with/other-characters/8846.31.4: false,
data-set-checkbox-test: 1,
]
gpus:
widget: number_field
Expand All @@ -187,6 +189,8 @@ attributes:
default: false
bc_email_on_started:
help: 'this is a help message should be hidden, sometimes'
checkbox_test:
widget: check_box
form:
- bc_num_hours
- bc_num_slots
Expand All @@ -205,3 +209,4 @@ form:
- auto_modules_app_jupyter
- auto_modules_intel
- auto_modules_netcdf-serial
- checkbox_test
3 changes: 2 additions & 1 deletion apps/dashboard/test/models/batch_connect/session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ def completed?
'advanced_options' => '',
'auto_modules_app_jupyter' => '',
'auto_modules_intel' => '',
'auto_modules_netcdf_serial' => ''
'auto_modules_netcdf_serial' => '',
'checkbox_test' => '',
}

assert session.save(app: bc_jupyter_app, context: ctx), session.errors.each(&:to_s).to_s
Expand Down
20 changes: 20 additions & 0 deletions apps/dashboard/test/system/batch_connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,26 @@ def make_bc_app(dir, form)
assert_equal 'display: none;', find_option_style('classroom_size', 'large')
end

test 'options can check and uncheck' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')

# defaults
assert_equal('small', find_value('classroom_size'))
refute(checked?('checkbox_test'))

# select large and it's checked
select('large', from: bc_ele_id('classroom_size'))
assert(checked?('checkbox_test'))

# back to small and it's unchanged
select('small', from: bc_ele_id('classroom_size'))
assert(checked?('checkbox_test'))

# now choose medium and it's un-checked
select('medium', from: bc_ele_id('classroom_size'))
refute(checked?('checkbox_test'))
end

test 'stage errors are shown' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
err_msg = 'this is a just a test for staging error messages'
Expand Down

0 comments on commit 1f7381a

Please sign in to comment.