Skip to content

Commit

Permalink
🪲 Fix incorrect parson validation (#5703)
Browse files Browse the repository at this point in the history
Fixes #5430
In puzzles, sometime the second exercise is not validated correctly because hidden elements get in the way of the correctness check.

**How to test**
Open the puzzle of level 5 and do the first exercise. Go to the second exercise and try to submit a correct answer.
  • Loading branch information
boryanagoncharenko authored Aug 19, 2024
1 parent 2b504c5 commit 882bbc3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -103861,8 +103861,10 @@ def note_with_error(value, err):
let code = "";
let order = new Array();
let mistake = false;
let hiddenElementsCount = 0;
document.querySelectorAll("#parsons_code_container > div > div").forEach((element, key) => {
if (!$(element).is(":visible")) {
hiddenElementsCount += 1;
return;
}
const parent = element.parentElement;
Expand All @@ -103873,7 +103875,7 @@ def note_with_error(value, err):
parent.classList.remove("border-green-500");
parent.classList.remove("border-red-500");
const index3 = element.dataset["index"] || 999;
if (index3 == key + 1) {
if (index3 == key + 1 - hiddenElementsCount) {
parent.classList.add("border-green-500");
} else {
mistake = true;
Expand Down
4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions static/js/parsons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ export function get_parsons_code() {
let code = "";
let order = new Array();
let mistake = false;
let hiddenElementsCount = 0;
document.querySelectorAll<HTMLElement>('#parsons_code_container > div > div').forEach((element, key) => {
// We are not interested in elements that are hidden
if (!$(element).is(':visible')) {
hiddenElementsCount += 1;
return;
}
// the parent is the one that has the borders...
Expand All @@ -131,7 +133,7 @@ export function get_parsons_code() {
parent.classList.remove('border-green-500');
parent.classList.remove('border-red-500');
const index = element.dataset['index'] || 999;
if (index == key + 1) {
if (index == key + 1 - hiddenElementsCount) {
parent.classList.add('border-green-500');
} else {
mistake = true;
Expand Down Expand Up @@ -172,4 +174,4 @@ export function initializeParsons() {
const editor = editorCreator.initializeReadOnlyEditor(container as HTMLElement, 'ltr');
editorDict[i + 1] = editor;
})
}
}

0 comments on commit 882bbc3

Please sign in to comment.