fix: Align question types and add Previous button to assessment
This commit is contained in:
parent
21204d2682
commit
38bf3e4b4d
2 changed files with 35 additions and 3 deletions
|
|
@ -38,6 +38,7 @@
|
||||||
var $questionsContainer = $('#quiztech-questions-container');
|
var $questionsContainer = $('#quiztech-questions-container');
|
||||||
var $questionContainers = $questionsContainer.find('.quiztech-question-container');
|
var $questionContainers = $questionsContainer.find('.quiztech-question-container');
|
||||||
var $timerDisplay = $('#quiztech-timer');
|
var $timerDisplay = $('#quiztech-timer');
|
||||||
|
var $prevButton = $('#quiztech-prev-question'); // ADDED SELECTOR
|
||||||
var $nextButton = $('#quiztech-next-question');
|
var $nextButton = $('#quiztech-next-question');
|
||||||
var $submitAssessmentButton = $('#quiztech-submit-assessment');
|
var $submitAssessmentButton = $('#quiztech-submit-assessment');
|
||||||
var $completionMessage = $('#quiztech-completion-message');
|
var $completionMessage = $('#quiztech-completion-message');
|
||||||
|
|
@ -98,6 +99,7 @@
|
||||||
// Handle case with no questions if needed
|
// Handle case with no questions if needed
|
||||||
showMessage($assessmentMessages, 'No questions found for this assessment.', true);
|
showMessage($assessmentMessages, 'No questions found for this assessment.', true);
|
||||||
$timerDisplay.hide();
|
$timerDisplay.hide();
|
||||||
|
$prevButton.hide(); // ADDED
|
||||||
$nextButton.hide();
|
$nextButton.hide();
|
||||||
$submitAssessmentButton.hide();
|
$submitAssessmentButton.hide();
|
||||||
}
|
}
|
||||||
|
|
@ -201,8 +203,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ($input.is(':checkbox')) {
|
} else if ($input.is(':checkbox')) {
|
||||||
// Example for checkboxes (if added later) - might need array handling
|
// Collect values from all checked checkboxes with the same name
|
||||||
answer = $input.is(':checked') ? $input.val() : ''; // Simplistic, adjust if multiple checkboxes per question
|
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 {
|
} else {
|
||||||
answer = $input.val(); // For textarea, text input, select
|
answer = $input.val(); // For textarea, text input, select
|
||||||
}
|
}
|
||||||
|
|
@ -256,7 +263,7 @@
|
||||||
if ($input.is(':radio')) {
|
if ($input.is(':radio')) {
|
||||||
var groupName = $input.attr('name');
|
var groupName = $input.attr('name');
|
||||||
value = $assessmentForm.find('input[name="' + groupName + '"]:checked').val();
|
value = $assessmentForm.find('input[name="' + groupName + '"]:checked').val();
|
||||||
} else {
|
} else { // Includes textarea, text, number, etc.
|
||||||
value = $input.val();
|
value = $input.val();
|
||||||
}
|
}
|
||||||
if (!value) {
|
if (!value) {
|
||||||
|
|
@ -264,6 +271,8 @@
|
||||||
// Maybe add a visual cue near the input?
|
// 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) {
|
if (!isValid) {
|
||||||
showMessage($assessmentMessages, 'Please answer the current question before proceeding.', true);
|
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() {
|
function updateNavigationButtons() {
|
||||||
if (totalQuestions <= 0) {
|
if (totalQuestions <= 0) {
|
||||||
|
$prevButton.hide();
|
||||||
$nextButton.hide();
|
$nextButton.hide();
|
||||||
$submitAssessmentButton.hide();
|
$submitAssessmentButton.hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Previous Button Visibility
|
||||||
|
if (currentQuestionIndex > 0) {
|
||||||
|
$prevButton.show();
|
||||||
|
} else {
|
||||||
|
$prevButton.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next/Submit Button Visibility
|
||||||
if (currentQuestionIndex >= totalQuestions - 1) {
|
if (currentQuestionIndex >= totalQuestions - 1) {
|
||||||
// Last question
|
// Last question
|
||||||
$nextButton.hide();
|
$nextButton.hide();
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ $show_pre_screening = ! empty( $pre_screening_questions ) && is_array( $pre_scre
|
||||||
</div> <!-- #quiztech-questions-container -->
|
</div> <!-- #quiztech-questions-container -->
|
||||||
|
|
||||||
<div class="quiztech-navigation">
|
<div class="quiztech-navigation">
|
||||||
|
<button type="button" id="quiztech-prev-question" style="display: none;"><?php esc_html_e( 'Previous Question', 'quiztech' ); ?></button> <?php // ADDED BUTTON ?>
|
||||||
<button type="button" id="quiztech-next-question"><?php esc_html_e( 'Next Question', 'quiztech' ); ?></button>
|
<button type="button" id="quiztech-next-question"><?php esc_html_e( 'Next Question', 'quiztech' ); ?></button>
|
||||||
<button type="button" id="quiztech-submit-assessment" style="display: none;"><?php esc_html_e( 'Submit Assessment', 'quiztech' ); ?></button>
|
<button type="button" id="quiztech-submit-assessment" style="display: none;"><?php esc_html_e( 'Submit Assessment', 'quiztech' ); ?></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue