From ddcb718a3ac4303a5bd0e201c16b67adabd638cd Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 23 Nov 2023 11:50:22 +0530 Subject: [PATCH] fix: quiz submission questions --- lms/lms/doctype/lms_quiz/lms_quiz.py | 2 +- lms/templates/quiz/quiz.js | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lms/lms/doctype/lms_quiz/lms_quiz.py b/lms/lms/doctype/lms_quiz/lms_quiz.py index bbaaabb7..80f0ab46 100644 --- a/lms/lms/doctype/lms_quiz/lms_quiz.py +++ b/lms/lms/doctype/lms_quiz/lms_quiz.py @@ -69,7 +69,7 @@ def quiz_summary(quiz, results): question_details = frappe.db.get_value( "LMS Quiz Question", - {"parent": quiz, "idx": result["question_index"] + 1}, + {"parent": quiz, "idx": result["question_index"]}, ["question", "marks"], as_dict=1, ) diff --git a/lms/templates/quiz/quiz.js b/lms/templates/quiz/quiz.js index 3491c5e4..3a86aa7b 100644 --- a/lms/templates/quiz/quiz.js +++ b/lms/templates/quiz/quiz.js @@ -4,6 +4,7 @@ frappe.ready(() => { this.answer = []; this.is_correct = []; this.show_answers = $("#quiz-title").data("show-answers"); + this.current_index = 0; localStorage.removeItem($("#quiz-title").data("name")); $(".btn-start-quiz").click((e) => { @@ -37,7 +38,6 @@ frappe.ready(() => { $("#next").click((e) => { e.preventDefault(); if (!this.show_answers) check_answer(); - mark_active_question(e); }); @@ -48,7 +48,7 @@ frappe.ready(() => { const mark_active_question = (e = undefined) => { let total_questions = $(".question").length; - let current_index = $(".active-question").attr("data-qt-index") || 0; + let current_index = this.current_index; let next_index = parseInt(current_index) + 1; if (this.show_answers) { @@ -170,7 +170,7 @@ const check_answer = (e = undefined) => { e && e.preventDefault(); let answer = $(".active-question textarea"); let total_questions = $(".question").length; - let current_index = $(".active-question").attr("data-qt-index"); + let current_index = this.current_index; if (answer.length && !answer.val().trim()) { frappe.throw(__("Please enter your answer")); @@ -188,6 +188,7 @@ const check_answer = (e = undefined) => { $("#next").removeClass("hide"); } parse_options(); + this.current_index += 1; }; const parse_options = () => { @@ -277,12 +278,10 @@ const add_icon = (element, icon) => { }; const add_to_local_storage = () => { - let current_index = $(".active-question").attr("data-qt-index"); let quiz_name = $("#quiz-title").data("name"); let quiz_stored = JSON.parse(localStorage.getItem(quiz_name)); - let quiz_obj = { - question_index: current_index - 1, + question_index: this.current_index, answer: self.answer.join(), is_correct: self.is_correct, };