Implemented the suggestion from http://moodle.org/mod/forum/discuss.php?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.

This commit is contained in:
mindforge
2005-06-22 11:21:46 +00:00
parent 0d6254cd8d
commit 88170baf19
2 changed files with 18 additions and 15 deletions
@@ -265,21 +265,21 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
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 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
// 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
@@ -192,17 +192,20 @@ class quiz_truefalse_qtype extends quiz_default_questiontype {
// 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 */