diff --git a/htdocs/js/AchievementList/achievementlist.js b/htdocs/js/AchievementList/achievementlist.js index 707393170e..08406848b1 100644 --- a/htdocs/js/AchievementList/achievementlist.js +++ b/htdocs/js/AchievementList/achievementlist.js @@ -63,7 +63,6 @@ const filter_select = document.getElementById('filter_select'); const filter = filter_select?.value || ''; const filter_text = document.getElementById('filter_text'); - const filter_category = document.getElementById('filter_category'); if (filter === 'selected' && !is_achievement_selected()) { e.preventDefault(); e.stopPropagation(); @@ -72,10 +71,6 @@ e.preventDefault(); e.stopPropagation(); show_errors(['filter_text_err_msg'], [filter_select, filter_text]); - } else if (filter === 'match_category' && filter_category?.value === '') { - e.preventDefault(); - e.stopPropagation(); - show_errors(['filter_category_err_msg'], [filter_select, filter_category]); } } else if (['edit', 'assign', 'export', 'score'].includes(action)) { const action_select = document.getElementById(`${action}_select`); diff --git a/lib/WeBWorK/DB.pm b/lib/WeBWorK/DB.pm index 4d59f2504c..0b12210adb 100644 --- a/lib/WeBWorK/DB.pm +++ b/lib/WeBWorK/DB.pm @@ -1290,6 +1290,11 @@ sub getAchievements { return $self->{achievement}->gets(map { [$_] } @achievementIDs); } +sub getAchievementCategories { + my ($self) = shift->checkArgs(\@_); + return map {@$_} $self->{achievement}->get_fields_where("DISTINCT category", undef, "category"); +} + sub addAchievement { my ($self, $Achievement) = shift->checkArgs(\@_, qw/REC:achievement/); diff --git a/templates/ContentGenerator/Instructor/AchievementList/filter_form.html.ep b/templates/ContentGenerator/Instructor/AchievementList/filter_form.html.ep index c4234f0309..f4537464f8 100644 --- a/templates/ContentGenerator/Instructor/AchievementList/filter_form.html.ep +++ b/templates/ContentGenerator/Instructor/AchievementList/filter_form.html.ep @@ -27,17 +27,17 @@
<%= maketext('Please enter a list of IDs to match.') %>
+ % my @categories = $c->db->getAchievementCategories; + % for (@categories) { + % $_ = [$_ => $_]; + % }
<%= label_for 'filter_category', class => 'col-form-label col-form-label-sm col-sm-auto', begin =%> - <%= maketext('Match on which category? (enter in exact match)') =%> - * + <%= maketext('Match on which category?') =%> <% end =%>
- <%= text_field 'action.filter.category' => '', id => 'filter_category', 'aria-required' => 'true', - class => 'form-control form-control-sm', dir => 'ltr' =%> + <%= select_field 'action.filter.category' => \@categories, + id => 'filter_category', class => 'form-select form-select-sm' =%>
-
- <%= maketext('Please enter a category to match.') %> -