bdaloukas / moodle-mod_game

moodle-mod_game
GNU General Public License v3.0
15 stars 40 forks source link

Crossword not working if you have two or more words in the same row/column #61

Closed zmartinovic closed 7 months ago

zmartinovic commented 8 months ago

There is a problem with referencing a question when you have tow or more words in the same row/column. In this case we get JS error and you can't enter an answer. Problem is in how crossword references questions in legend and how it references it in JS code. In legend if there is multiple words in the same row/column it will append letter to it (for example 8A, 8B, 8C...):

$this->mlegendh[$key.game_substr( $letters, $i, 1)] = $value[$i];
$this->mlegendv[$key.game_substr( $letters, $i, 1)] = $value[$i];

so it will create a DIV with that id:

<div id="a8A">
<div id="a8B">

but array passed to JS only refers to row/coll:

$swordx .= ",".($rec->mycol - 1);
$swordy .= ",".($rec->myrow - 1);

This is a problem because now you can't reference created DIV elements:

if( CurrentWord <= LastHorizontalWord) {
    id = 'a' + ( 1 + WordY[ CurrentWord]);
} else {
    id = 'd' + ( 1 + WordX[ CurrentWord]);
}
document.getElementById("wordclue").innerHTML = document.getElementById( id).innerHTML;

var id will only have value "a8" but there is DIV element with this id. sc1 sc2 sc3

bdaloukas commented 7 months ago

Version 2023111400 fixes the above problem.