diff --git a/generic/widgets.py b/generic/widgets.py
index ea1020ed..64e5764e 100644
--- a/generic/widgets.py
+++ b/generic/widgets.py
@@ -484,7 +484,7 @@ class ExamSearchSelectMultipleWidget:
{selected_html}
-
+
@@ -568,16 +568,25 @@ class ExamSearchSelectMultipleWidget:
}});
}}
- // Delegate add clicks from results
+ // Delegate clicks from results: add single or add-all (works for dynamically inserted content)
results.addEventListener('click', function(e) {{
- const btn = e.target.closest('.exam-add-btn');
- if (!btn) return;
- const id = btn.getAttribute('data-exam-id');
- const text = btn.getAttribute('data-exam-text') || btn.textContent.trim();
- addExamToField(widgetFieldName, id, text);
+ const addBtn = e.target.closest('.exam-add-btn');
+ if (addBtn) {{
+ const id = addBtn.getAttribute('data-exam-id');
+ const text = addBtn.getAttribute('data-exam-text') || addBtn.textContent.trim();
+ addExamToField(widgetFieldName, id, text);
+ return;
+ }}
+ const addAllBtnDynamic = e.target.closest('.exam-add-all-btn');
+ if (addAllBtnDynamic) {{
+ e.preventDefault();
+ addAllExamsFromResults(widgetFieldName);
+ return;
+ }}
}});
- // Wire up "Add all results" button if present
+
+ // Wire up "Add all results" static button if present (fallback)
const addAllBtn = results.parentElement.querySelector('.exam-add-all-btn');
if (addAllBtn) {{
addAllBtn.addEventListener('click', function(e) {{
@@ -586,6 +595,15 @@ class ExamSearchSelectMultipleWidget:
}});
}}
+ // Initialize remove-all visibility based on any pre-populated selections
+ try {{
+ var initList = document.getElementById('selected_exams_' + widgetFieldName);
+ var remBtnInit = document.getElementById('exam_remove_all_' + widgetFieldName);
+ if (remBtnInit && initList) {{
+ remBtnInit.classList.toggle('d-none', initList.querySelectorAll('li').length < 2);
+ }}
+ }} catch (e) {{ /* ignore in older browsers */ }}
+
// Wire up "Remove all" button for this widget instance
const removeAllBtn = document.getElementById('exam_remove_all_' + widgetFieldName);
if (removeAllBtn) {{