Skip to content

Commit

Permalink
correctly handle options that start with numbers (#3241)
Browse files Browse the repository at this point in the history
correctly handle dynamic batch connect options that start with numbers.
  • Loading branch information
johrstrom authored Jan 2, 2024
1 parent f97c901 commit c750ad2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/dashboard/app/javascript/dynamic_forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ function optionForFromToken(str) {
}

let optionForValue = mountainCaseWords(document.getElementById(optionForId).value);
// handle special case where the very first token here is a number.
// browsers expect a prefix of hyphens as if it's the next token.
if (optionForValue.match(/^\d/)) {
optionForValue = `-${optionForValue}`;
}

hide = option.dataset[`optionFor${optionFor}${optionForValue}`] === 'false';
if (hide) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ attributes:
data-min-bc-num-hours-for-cluster-oakley: 111,
]
- [ 'Economics 8846', 'astronomy-with/other-characters/8846.31.4' ]
- [ '123ABC', '123ABC' ]
- [ '456def', '456def' ]
classroom_size:
widget: select
options:
Expand All @@ -179,6 +181,8 @@ attributes:
data-option-for-classroom-astronomy-5678: false,
data-option-for-classroom-astronomy-with/other-characters/8846.31.4: false,
data-set-checkbox-test: 1,
data-option-for-classroom-123ABC: false,
data-option-for-classroom-456def: false,
]
gpus:
widget: number_field
Expand Down
21 changes: 21 additions & 0 deletions apps/dashboard/test/system/batch_connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,27 @@ def make_bc_app(dir, form)
find("##{bc_ele_id('bc_email_on_started')}", visible: false)
end

test 'options that start with numbers hide other options' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')

# defaults
assert_equal('physics_1234', find_value('classroom'))
assert_equal('small', find_value('classroom_size'))
assert_equal('', find_option_style('classroom_size', 'large'))

# now change the classroom and see large dissappear
select('123ABC', from: bc_ele_id('classroom'))
assert_equal('display: none;', find_option_style('classroom_size', 'large'))

# select the default, and it's back.
select('Physics 1234', from: bc_ele_id('classroom'))
assert_equal('', find_option_style('classroom_size', 'large'))

# now change the lowercase classroom and see large dissappear again.
select('456def', from: bc_ele_id('classroom'))
assert_equal('display: none;', find_option_style('classroom_size', 'large'))
end

test 'options with numbers and slashes' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')

Expand Down

0 comments on commit c750ad2

Please sign in to comment.