Skip to content

Commit

Permalink
Also make sure that the selection is preserved on the "Sets Manager"
Browse files Browse the repository at this point in the history
page when the available options change.
  • Loading branch information
drgrice1 committed Apr 13, 2024
1 parent e4e9c52 commit 2d3b546
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions htdocs/js/ProblemSetList/problemsetlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@
const allOptions = Array.from(importSourceSelect.options);

const updateAvailableOptions = () => {
// Save the currently selected options.
const selectedDefs = Array.from(importSourceSelect.selectedOptions);

for (const option of Array.from(importSourceSelect.options)) option.value && option.remove();
for (const option of allOptions) {
if (option.value.startsWith('Library/')) {
Expand All @@ -294,6 +297,17 @@
if (listContribSetsCheck.checked) importSourceSelect.add(option);
} else importSourceSelect.add(option);
}

// Reselect the options that were selected before if still available. Otherwise
// select the first option which should be the "Select filenames below" option.
let foundSelected = false;
for (const option of importSourceSelect.options) {
if (selectedDefs.includes(option)) {
foundSelected = true;
option.selected = true;
}
}
if (!foundSelected) allOptions[0].selected = true;
};

listOPLSetsCheck?.addEventListener('change', updateAvailableOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class => 'col-form-label col-form-label-sm col-md-auto' =%>
<div class="col-auto">
<%= select_field 'action.import.source' => [
[ maketext('Enter filenames below') => '', selected => undef ],
[ maketext('Select filenames below') => '', selected => undef, disabled => undef ],
@$setDefList
],
id => 'import_source_select', class => 'form-select form-select-sm', dir => 'ltr',
Expand Down

0 comments on commit 2d3b546

Please sign in to comment.