diff --git a/public/js/assessment.js b/public/js/assessment.js index 5f2fc9b..96604ff 100644 --- a/public/js/assessment.js +++ b/public/js/assessment.js @@ -38,6 +38,7 @@ var $questionsContainer = $('#quiztech-questions-container'); var $questionContainers = $questionsContainer.find('.quiztech-question-container'); var $timerDisplay = $('#quiztech-timer'); + var $prevButton = $('#quiztech-prev-question'); // ADDED SELECTOR var $nextButton = $('#quiztech-next-question'); var $submitAssessmentButton = $('#quiztech-submit-assessment'); var $completionMessage = $('#quiztech-completion-message'); @@ -98,6 +99,7 @@ // Handle case with no questions if needed showMessage($assessmentMessages, 'No questions found for this assessment.', true); $timerDisplay.hide(); + $prevButton.hide(); // ADDED $nextButton.hide(); $submitAssessmentButton.hide(); } @@ -201,8 +203,13 @@ } } } else if ($input.is(':checkbox')) { - // Example for checkboxes (if added later) - might need array handling - answer = $input.is(':checked') ? $input.val() : ''; // Simplistic, adjust if multiple checkboxes per question + // Collect values from all checked checkboxes with the same name + var groupName = $input.attr('name'); + var checkedValues = []; + $assessmentForm.find('input[name="' + groupName + '"]:checked').each(function() { + checkedValues.push($(this).val()); + }); + answer = JSON.stringify(checkedValues); // Store as JSON string } else { answer = $input.val(); // For textarea, text input, select } @@ -256,7 +263,7 @@ if ($input.is(':radio')) { var groupName = $input.attr('name'); value = $assessmentForm.find('input[name="' + groupName + '"]:checked').val(); - } else { + } else { // Includes textarea, text, number, etc. value = $input.val(); } if (!value) { @@ -264,6 +271,8 @@ // Maybe add a visual cue near the input? } }); + // Note: Checkbox groups might not have 'required' on individual inputs, + // validation logic might need adjustment if a checkbox answer is mandatory. if (!isValid) { showMessage($assessmentMessages, 'Please answer the current question before proceeding.', true); @@ -281,12 +290,34 @@ } }); + // ADDED: Previous Button Handler + $prevButton.on('click', function() { + if (currentQuestionIndex > 0) { + clearMessage($assessmentMessages); // Clear any messages + // Hide current, show previous + $questionContainers.eq(currentQuestionIndex).addClass('quiztech-question-hidden'); + currentQuestionIndex--; + $questionContainers.eq(currentQuestionIndex).removeClass('quiztech-question-hidden'); + updateNavigationButtons(); + } + }); + function updateNavigationButtons() { if (totalQuestions <= 0) { + $prevButton.hide(); $nextButton.hide(); $submitAssessmentButton.hide(); return; } + + // Previous Button Visibility + if (currentQuestionIndex > 0) { + $prevButton.show(); + } else { + $prevButton.hide(); + } + + // Next/Submit Button Visibility if (currentQuestionIndex >= totalQuestions - 1) { // Last question $nextButton.hide(); diff --git a/public/templates/assessment-shell.php b/public/templates/assessment-shell.php index 5dcfce3..ada4200 100644 --- a/public/templates/assessment-shell.php +++ b/public/templates/assessment-shell.php @@ -240,6 +240,7 @@ $show_pre_screening = ! empty( $pre_screening_questions ) && is_array( $pre_scre