diff --git a/htdocs/js/ProblemSetDetail/problemsetdetail.js b/htdocs/js/ProblemSetDetail/problemsetdetail.js index 49a0c58d13..2f46256fc0 100644 --- a/htdocs/js/ProblemSetDetail/problemsetdetail.js +++ b/htdocs/js/ProblemSetDetail/problemsetdetail.js @@ -414,4 +414,10 @@ comboBoxSelect.addEventListener('change', () => comboBoxText.value = comboBoxSelect.options[comboBoxSelect.selectedIndex].value); }); + + // Set up seed randomization buttons. + for (const btn of document.querySelectorAll('.randomize-seed-btn')) { + const input = document.getElementById(btn.dataset.seedInput); + if (input) btn.addEventListener('click', () => (input.value = Math.floor(Math.random() * 10000))); + } })(); diff --git a/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm b/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm index 07d08d098d..9c1bf712a2 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm @@ -950,22 +950,22 @@ sub fieldHTML ($c, $userID, $setID, $problemID, $globalRecord, $userRecord, $fie ); if ($field eq 'problem_seed') { # Insert a randomization button - $inputType = Mojo::ByteStream->new($c->tag( + $inputType = $c->tag( 'div', class => 'input-group input-group-sm', style => 'min-width: 7rem', - $c->number_field(@field_args, min => 0)->to_string - . $c->tag( + $c->c( + $c->number_field(@field_args, min => 0), + $c->tag( 'button', - type => 'button', - class => 'btn btn-sm btn-secondary', - title => 'randomize', - onclick => - "(function() {document.getElementById('$recordType.$recordID.${field}_id').value = Math.floor(Math.random() * 10000);})();", + type => 'button', + class => 'randomize-seed-btn btn btn-sm btn-secondary', + title => 'randomize', + data => { seed_input => "$recordType.$recordID.${field}_id" }, $c->tag('i', class => 'fa-solid fa-shuffle') ) - ))->html_unescape; - warn(ref($inputType)); + )->join('') + ); } else { $inputType = $c->text_field(@field_args); }