Skip to content

Commit

Permalink
Reselect the selected set definition file after re-adding the options.
Browse files Browse the repository at this point in the history
The default disabled "Select a Set Definition File" needs to always be
present so that if an option is no longer available due to one of the
"List OPL Sets" or "List Contrib Sets" check boxes being unchecked after
selecting one of those set definition files, then the default can be
selected again.
  • Loading branch information
drgrice1 committed Apr 13, 2024
1 parent ba7de1d commit e4e9c52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 10 additions & 0 deletions htdocs/js/SetMaker/setmaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,24 @@
const allOptions = Array.from(setDefSelect.options);

const updateAvailableOptions = () => {
// Save the currently selected option.
let selectedDef = setDefSelect.selectedOptions[0];

for (const option of Array.from(setDefSelect.options)) option.value && option.remove();
for (const option of allOptions) {
if (option.value.startsWith('Library/')) {
if (listOPLSetsCheck.checked) setDefSelect.add(option);
else if (selectedDef === option) selectedDef = null;
} else if (option.value.startsWith('Contrib/')) {
if (listContribSetsCheck.checked) setDefSelect.add(option);
else if (selectedDef === option) selectedDef = null;
} else setDefSelect.add(option);
}

// Reselect the option that was selected before if it is still available. Otherwise
// select the first option which should be the "Select a Set Defintion File" option.
if (selectedDef) selectedDef.selected = true;
else allOptions[0].selected = true;
};

listOPLSetsCheck?.addEventListener('change', updateAvailableOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
<div class="mb-2">
<label class="col-form-label-sm"><%= maketext('Browse from:') %></label>
<%= select_field library_sets => [
$selected_library eq '' ?
[ maketext('Select a Set Definition File') => '', selected => undef, disabled => 'disabled' ]
: (),
[
maketext('Select a Set Definition File') => '',
$selected_library ? () : (selected => undef),
disabled => undef
],
@list_of_set_defs
],
class => 'form-select form-select-sm d-inline w-auto' =%>
Expand Down

0 comments on commit e4e9c52

Please sign in to comment.