From f44f3bbcfefb05ce1b18919bc71c3279407ff885 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 5 Jan 2026 11:59:23 +0000 Subject: [PATCH] Enhance exam navigation by adding a skip button for non-saving question transitions and implementing unsaved changes confirmation. --- .../physics/partials/exam_take_fragment.html | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/physics/templates/physics/partials/exam_take_fragment.html b/physics/templates/physics/partials/exam_take_fragment.html index f0d36e4e..7487cb46 100644 --- a/physics/templates/physics/partials/exam_take_fragment.html +++ b/physics/templates/physics/partials/exam_take_fragment.html @@ -60,7 +60,13 @@ {% endif %} {% if next %} - + + + + + {% else %} {% if not exam.publish_results %} @@ -128,6 +134,58 @@ document.getElementById('goto-button').value = e.currentTarget.dataset.qn; $('#goto-button').click(); }); + + // Skip confirmation: if the user's current selections differ from + // the saved answer, prompt before allowing the HTMX skip to proceed. + (function(){ + const skip = document.getElementById('skip-button'); + if(!skip) return; + + // Build a JS array of saved answers (booleans) or null + {% if saved_answer %} + const savedAnswers = [{% for s in saved_answer %}{{ s|yesno:"true,false" }}{% if not forloop.last %}, {% endif %}{% endfor %}]; + {% else %} + const savedAnswers = null; + {% endif %} + + function readCurrent(){ + const lis = document.querySelectorAll('ol.physics-answer-list li'); + return Array.from(lis).map(li => { + const inp = li.querySelector('input'); + return !!(inp && inp.checked); + }); + } + + skip.addEventListener('click', function(evt){ + try{ + const current = readCurrent(); + let changed = false; + if(savedAnswers === null){ + // no previously-saved answer; any current selection is a change + changed = current.some(Boolean); + } else { + if(current.length === savedAnswers.length){ + for(let i=0;i