Skip to content

Commit e15933a

Browse files
committed
fix: don't call addIframeFormDataOnSubmit if readonly
Removes the error message due to there not being a form around the iframe. We disable all inputs anyway when readonly. Fixes: #183
1 parent 63e3cf2 commit e15933a

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

renderer.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,17 @@ public function formulation_and_controls(question_attempt $qa, question_display_
8989
};
9090
$iframesrc = $this->get_iframe_document($options->context, $question, $formulationcb);
9191

92-
// A hidden input field is used to tell the quiz autosaver that the user changed their question answer
93-
// in the iframe. The value is increased by one every time. The autosaver detects this modification and will
94-
// save all answers.
9592
$iframeid = $questiondivid . '-iframe';
96-
$autosavehintname = 'qpy-autosave-' . $questiondivid;
97-
$this->page->requires->js_call_amd(
98-
'qtype_questionpy/view_question',
99-
'addIframeFormDataOnSubmit',
100-
[$iframeid, $qa->get_field_prefix() . constants::QT_VAR_RESPONSE]
101-
);
10293

103-
$result = '';
94+
if (!$options->readonly) {
95+
$this->page->requires->js_call_amd(
96+
'qtype_questionpy/view_question',
97+
'addIframeFormDataOnSubmit',
98+
[$iframeid, $qa->get_field_prefix() . constants::QT_VAR_RESPONSE]
99+
);
100+
}
104101

102+
$result = '';
105103
if (
106104
($options->qpyattemptdetailslink ?? question_display_options::VISIBLE) === question_display_options::VISIBLE
107105
&& has_capability(constants::ROLE_VIEW_DETAILS, $options->context)
@@ -114,6 +112,11 @@ public function formulation_and_controls(question_attempt $qa, question_display_
114112
. get_string('attempt_detail_link', 'qtype_questionpy') . '</a>';
115113
}
116114

115+
// A hidden input field is used to tell the quiz autosaver that the user changed their question answer
116+
// in the iframe. The value is increased by one every time. The autosaver detects this modification and will
117+
// save all answers.
118+
$autosavehintname = 'qpy-autosave-' . $questiondivid;
119+
117120
$result .= <<<EOA
118121
<input type="hidden" name="{$autosavehintname}" id="{$autosavehintid}" value="0">
119122
<iframe id="{$iframeid}" srcdoc="{$iframesrc}"></iframe>

0 commit comments

Comments
 (0)