Skip to content

Commit eb7a8d2

Browse files
committed
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.
1 parent 07f5b04 commit eb7a8d2

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

htdocs/js/ProblemSetList/problemsetlist.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,22 @@
139139
filter_select?.addEventListener('change', filterElementToggle);
140140

141141
// This will make the popup menu alternate between a single selection and a multiple selection menu.
142-
const importAmtSelect = document.getElementById('import_amt_select');
143-
if (importAmtSelect) {
144-
importAmtSelect.addEventListener('change', () => {
145-
const numSelect = document.problemsetlist['action.import.number'];
146-
const number = parseInt(numSelect.options[numSelect.selectedIndex].value);
147-
document.problemsetlist['action.import.source'].size = number;
148-
document.problemsetlist['action.import.source'].multiple = number > 1 ? true : false;
149-
document.problemsetlist['action.import.name'].value = number > 1 ? '(taken from filenames)' : '';
150-
document.problemsetlist['action.import.name'].readOnly = number > 1 ? true : false;
151-
document.problemsetlist['action.import.name'].disabled = number > 1 ? true : false;
142+
const numSelect = document.problemsetlist['action.import.number'];
143+
if (numSelect) {
144+
numSelect.addEventListener('change', () => {
145+
const number = parseInt(numSelect.options[numSelect.selectedIndex]?.value ?? '1');
146+
const importSourceSelect = document.problemsetlist['action.import.source'];
147+
if (importSourceSelect) {
148+
importSourceSelect.size = number;
149+
importSourceSelect.multiple = number > 1 ? true : false;
150+
if (number > 1) importSourceSelect.options[0].selected = false;
151+
}
152+
const importNameInput = document.problemsetlist['action.import.name'];
153+
if (importNameInput) {
154+
importNameInput.value = number > 1 ? '(taken from filenames)' : '';
155+
importNameInput.readOnly = number > 1 ? true : false;
156+
importNameInput.disabled = number > 1 ? true : false;
157+
}
152158
});
153159
}
154160

0 commit comments

Comments
 (0)