diff --git a/htdocs/js/ProblemSetList/problemsetlist.js b/htdocs/js/ProblemSetList/problemsetlist.js index c980d76c22..c2802ebc9e 100644 --- a/htdocs/js/ProblemSetList/problemsetlist.js +++ b/htdocs/js/ProblemSetList/problemsetlist.js @@ -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/')) { @@ -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); diff --git a/templates/ContentGenerator/Instructor/ProblemSetList/import_form.html.ep b/templates/ContentGenerator/Instructor/ProblemSetList/import_form.html.ep index 844554d518..44b9de5075 100644 --- a/templates/ContentGenerator/Instructor/ProblemSetList/import_form.html.ep +++ b/templates/ContentGenerator/Instructor/ProblemSetList/import_form.html.ep @@ -15,7 +15,7 @@ class => 'col-form-label col-form-label-sm col-md-auto' =%>