Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented the suggestion from http://moodle.org/mod/forum/discuss.p…

…hp?d=26139. The label element is now used in the multichoice and truefalse questiontypes in order to allow clicking on the answer text to select the according checkbox/radiobutton.
  • Loading branch information...
commit 88170baf19dceac370aaab862c0042a0eb677d8d 1 parent 0d6254c
mindforge authored
View
20 mod/quiz/questiontypes/multichoice/questiontype.php
@@ -265,21 +265,21 @@ function print_question_formulation_and_controls(&$question, &$state, $quiz, $op
if ($question->options->single) {
$type = 'type="radio"';
- $name = "name=\"{$question->name_prefix}\"";
+ $id = $question->name_prefix;
$checked = $aid == $state->responses['']
? 'checked="checked"' : '';
} else {
$type = ' type="checkbox" ';
- $name = "name=\"{$question->name_prefix}$aid\"";
+ $id = $question->name_prefix . $aid;
$checked = isset($state->responses[$aid])
? 'checked="checked"' : '';
}
-
+ $name = "name=\"$id\"";
+ $fullid = "id=\"$id\"";
// Print the control
- echo "<input $readonly $name $checked $type value=\"$aid\" alt=\""
- . s($answer->answer) . '" />';
-
+ echo "<input $readonly $fullid $name $checked $type value=\"$aid\"" .
+ "alt=\"" . s($answer->answer) . '" />';
echo '</td>';
// Print the text by the control highlighting if correct responses
@@ -288,13 +288,13 @@ function print_question_formulation_and_controls(&$question, &$state, $quiz, $op
// selection case
if ($options->readonly && $options->correct_responses &&
in_array($aid, $correctanswers)) {
- echo '<td valign="top" class="highlight">' .
+ echo '<td valign="top" class="highlight"><label for="'.$id.'">'.
format_text("$qnumchar. $answer->answer", FORMAT_MOODLE ,
- $formatoptions) . '</td>';
+ $formatoptions) . '</label></td>';
} else {
- echo '<td valign="top">' .
+ echo '<td valign="top"><label for="'.$id.'">'.
format_text("$qnumchar. $answer->answer", FORMAT_MOODLE,
- $formatoptions) . '</td>';
+ $formatoptions) . '</label></td>';
}
// Print feedback by selected options if feedback is on
View
13 mod/quiz/questiontypes/truefalse/questiontype.php
@@ -192,17 +192,20 @@ function print_question_formulation_and_controls(&$question, &$state,
// Print the controls
$inputname = ' name="'.$question->name_prefix.'" ';
+ $trueid = $question->name_prefix.'true';
+ $falseid = $question->name_prefix.'false';
echo '<table align="right" cellpadding="5"><tr><td align="right">';
echo $stranswer . ':&nbsp;&nbsp;</td>';
echo '<td' . $truecorrect . '>';
echo '<input type="radio"' . $truechecked . $readonly . $inputname;
- echo 'value="' . $answers['true']->id . '" alt="';
- echo s($answers['true']->answer) . '" />' . s($answers['true']->answer);
+ echo 'id="'.$trueid . '" value="' . $answers['true']->id . '" alt="';
+ echo s($answers['true']->answer) . '" /><label for="'.$trueid . '">';
+ echo s($answers['true']->answer) . '</label>';
echo '</td><td' . $falsecorrect . '>';
echo '<input type="radio"' . $falsechecked . $readonly . $inputname;
- echo 'value="' . $answers['false']->id . '" alt="';
- echo s($answers['false']->answer) . '" />';
- p($answers['false']->answer);
+ echo 'id="'.$falseid . '" value="' . $answers['false']->id . '" alt="';
+ echo s($answers['false']->answer) . '" /><label for="'.$falseid . '">';
+ echo s($answers['false']->answer) . '</label>';
if (!empty($marked) && (!$options->readonly || $marked !== $selected)) {
/* This should never happen but it is here both for robustness and
to serve as an example for question type authors */
Please sign in to comment.
Something went wrong with that request. Please try again.