diff --git a/htdocs/js/ProblemSetList/problemsetlist.js b/htdocs/js/ProblemSetList/problemsetlist.js index 39d9964939..8bd082360a 100644 --- a/htdocs/js/ProblemSetList/problemsetlist.js +++ b/htdocs/js/ProblemSetList/problemsetlist.js @@ -139,16 +139,32 @@ 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; + if (number === 1) { + if (!importSourceSelect.value) importSourceSelect.options[0].selected = true; + importSourceSelect.options[0].textContent = + importSourceSelect.dataset.selectSingleText ?? 'Select filename below'; + importSourceSelect.multiple = false; + } else { + importSourceSelect.options[0].textContent = + importSourceSelect.dataset.selectMultipleText ?? 'Select filename below'; + importSourceSelect.multiple = true; + importSourceSelect.options[0].selected = false; + } + } + const importNameInput = document.problemsetlist['action.import.name']; + if (importNameInput) { + importNameInput.value = + number > 1 ? (importNameInput.dataset.multipleFilesText ?? '(taken from filenames)') : ''; + importNameInput.readOnly = number > 1 ? true : false; + importNameInput.disabled = number > 1 ? true : false; + } }); } diff --git a/templates/ContentGenerator/Instructor/ProblemSetList/import_form.html.ep b/templates/ContentGenerator/Instructor/ProblemSetList/import_form.html.ep index bd7ea75f91..60bff0fd19 100644 --- a/templates/ContentGenerator/Instructor/ProblemSetList/import_form.html.ep +++ b/templates/ContentGenerator/Instructor/ProblemSetList/import_form.html.ep @@ -15,11 +15,15 @@ class => 'col-form-label col-form-label-sm col-md-auto' =%>
<%= select_field 'action.import.source' => [ - [ maketext('Select filenames below') => '', selected => undef, disabled => undef ], + [ maketext('Select filename below') => '', selected => undef, disabled => undef ], @$setDefList ], id => 'import_source_select', class => 'form-select form-select-sm', dir => 'ltr', size => param('action.import.number') || 1, + data => { + select_multiple_text => maketext('Select filenames below'), + select_single_text => maketext('Select filename below') + }, defined param('action.import.number') && param('action.import.number') ne '1' ? (multiple => undef) : () =%> @@ -30,7 +34,7 @@ class => 'col-form-label col-form-label-sm col-md-auto' =%>
<%= text_field 'action.import.name' => '', id => 'import_text', class => 'form-control form-control-sm', - dir => 'ltr' =%> + dir => 'ltr', data => { multiple_files_text => maketext('(taken from filenames)') } =%>