From 730e9a542661895aa069b6316f4088782cacecab Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Wed, 7 Jan 2026 14:43:27 -0500 Subject: [PATCH] Fix sets manager import form selection multiple default option selected issue. Currently when the sets manager page loads the "Import how many sets?" select has "a single set" initially selected and the "Import from where?" select has "Select filenames below" selected. But then if you change the first select to "multiple sets" the "Import from where?" select still has "Select filenames below" selected. Furthermore, if you then click on that select and use shift-down arrow to select multiple sets, that first disabled option stays selected. Then form validation fails for that option since it has no value if you click the "Import" button. This just makes it so that when you switch from the "Import how many sets?" select from "a single set" to "multiple sets", that first option in the "Import from where?" select is immediately unselected. There is also a little clean up of this section of JavaScript code. The elements with id `import_source_select` and name `action.import.number` are actually the same element, so no need to find them in the DOM twice. Also ensure the elements exist and are found before trying to work with them. More of this is needed in this file, but this is probably good enough for now. --- htdocs/js/ProblemSetList/problemsetlist.js | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/htdocs/js/ProblemSetList/problemsetlist.js b/htdocs/js/ProblemSetList/problemsetlist.js index ca9f334853..42a0afc4a0 100644 --- a/htdocs/js/ProblemSetList/problemsetlist.js +++ b/htdocs/js/ProblemSetList/problemsetlist.js @@ -139,16 +139,22 @@ filter_select?.addEventListener('change', filterElementToggle); // This will make the popup menu alternate between a single selection and a multiple selection menu. - const importAmtSelect = document.getElementById('import_amt_select'); - if (importAmtSelect) { - importAmtSelect.addEventListener('change', () => { - const numSelect = document.problemsetlist['action.import.number']; - const number = parseInt(numSelect.options[numSelect.selectedIndex].value); - document.problemsetlist['action.import.source'].size = number; - document.problemsetlist['action.import.source'].multiple = number > 1 ? true : false; - document.problemsetlist['action.import.name'].value = number > 1 ? '(taken from filenames)' : ''; - document.problemsetlist['action.import.name'].readOnly = number > 1 ? true : false; - document.problemsetlist['action.import.name'].disabled = number > 1 ? true : false; + const numSelect = document.problemsetlist['action.import.number']; + if (numSelect) { + numSelect.addEventListener('change', () => { + const number = parseInt(numSelect.options[numSelect.selectedIndex]?.value ?? '1'); + const importSourceSelect = document.problemsetlist['action.import.source']; + if (importSourceSelect) { + importSourceSelect.size = number; + importSourceSelect.multiple = number > 1 ? true : false; + if (number > 1) importSourceSelect.options[0].selected = false; + } + const importNameInput = document.problemsetlist['action.import.name']; + if (importNameInput) { + importNameInput.value = number > 1 ? '(taken from filenames)' : ''; + importNameInput.readOnly = number > 1 ? true : false; + importNameInput.disabled = number > 1 ? true : false; + } }); }