Skip to content

Commit

Permalink
Test: Fix Enter in Question-Form for Non Edit Cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
kergomard committed Apr 16, 2024
1 parent ee9c2af commit b16cacd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected function setQuestionSpecificTabs(ilTabsGUI $ilTabs): void
protected function callSpecialQuestionCommands(string $cmd): void
{
if (preg_match('/suggestrange_(\$r\d+)/', $cmd, $matches)) {
$this->addSaveOnEnterOnLoadCode();
$this->suggestRange($matches[1]);
}
}
Expand Down Expand Up @@ -738,6 +739,7 @@ private function canUseAdvancedRating($result): bool
public function parseQuestion(): void
{
$this->writePostData();
$this->addSaveOnEnterOnLoadCode();
$this->editQuestion();
}

Expand Down
32 changes: 19 additions & 13 deletions Modules/TestQuestionPool/classes/class.assQuestionGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,11 @@ public function executeCommand()
case 'addGIT':
$this->$cmd();
break;
case 'save':
case 'saveReturn':
case 'editQuestion':
$this->tpl->addOnloadCode("
let form = document.querySelector('#ilContentContainer form');
let button = form.querySelector('input[name=\"cmd[save]\"]');
if (form && button) {
form.addEventListener('keydown', function (e) {
if (e.key === 'Enter' && e.target.type !== 'textarea') {
e.preventDefault();
form.requestSubmit(button);
}
})
}
");
$this->editQuestion();
$this->addSaveOnEnterOnLoadCode();
$this->$cmd();
break;
default:
if (method_exists($this, $cmd)) {
Expand Down Expand Up @@ -2046,4 +2037,19 @@ public function setInLearningModuleContext(bool $flag): void
$this->parent_type_is_lm = $flag;
}

protected function addSaveOnEnterOnLoadCode(): void
{
$this->tpl->addOnloadCode("
let form = document.querySelector('#ilContentContainer form');
let button = form.querySelector('input[name=\"cmd[save]\"]');
if (form && button) {
form.addEventListener('keydown', function (e) {
if (e.key === 'Enter' && e.target.type !== 'textarea') {
e.preventDefault();
form.requestSubmit(button);
}
})
}
");
}
}

0 comments on commit b16cacd

Please sign in to comment.