diff --git a/htdocs/js/SetMaker/setmaker.js b/htdocs/js/SetMaker/setmaker.js index a505ac4286..f358bfc874 100644 --- a/htdocs/js/SetMaker/setmaker.js +++ b/htdocs/js/SetMaker/setmaker.js @@ -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); diff --git a/templates/ContentGenerator/Instructor/SetMaker/browse_setdef_panel.html.ep b/templates/ContentGenerator/Instructor/SetMaker/browse_setdef_panel.html.ep index 435b85f846..7569eb7c68 100644 --- a/templates/ContentGenerator/Instructor/SetMaker/browse_setdef_panel.html.ep +++ b/templates/ContentGenerator/Instructor/SetMaker/browse_setdef_panel.html.ep @@ -15,9 +15,11 @@
<%= 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' =%>