Skip to content

Commit

Permalink
fix: quiz submission questions
Browse files Browse the repository at this point in the history
  • Loading branch information
pateljannat committed Nov 23, 2023
1 parent a17a745 commit ddcb718
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lms/lms/doctype/lms_quiz/lms_quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
11 changes: 5 additions & 6 deletions lms/templates/quiz/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -37,7 +38,6 @@ frappe.ready(() => {
$("#next").click((e) => {
e.preventDefault();
if (!this.show_answers) check_answer();

mark_active_question(e);
});

Expand All @@ -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) {
Expand Down Expand Up @@ -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"));
Expand All @@ -188,6 +188,7 @@ const check_answer = (e = undefined) => {
$("#next").removeClass("hide");
}
parse_options();
this.current_index += 1;
};

const parse_options = () => {
Expand Down Expand Up @@ -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,
};
Expand Down

0 comments on commit ddcb718

Please sign in to comment.