Skip to content

Commit

Permalink
MDL-34570 accessibility compliance for question: edit string label
Browse files Browse the repository at this point in the history
  • Loading branch information
Rossiani Wijaya authored and Frederic Massart committed Sep 28, 2012
1 parent 5d6285c commit 8369017
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 14 deletions.
3 changes: 2 additions & 1 deletion question/behaviour/rendererbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ public function manual_comment_fields(question_attempt $qa, question_display_opt
array('id' => $id, 'name' => $inputname, 'rows' => 10, 'cols' => 60)));

$commenteditor .= html_writer::start_tag('div');
if (count($formats == 1)) {
if (count($formats) == 1) {
reset($formats);
$commenteditor .= html_writer::empty_tag('input', array('type' => 'hidden',
'name' => $inputname . 'format', 'value' => key($formats)));

} else {
$commenteditor .= html_writer::label(get_string('formattexttype'), 'menu' . $inputname . 'format', false, array('class' => 'accesshide'));
$commenteditor .= html_writer::select(
$formats, $inputname . 'format', $commentformat, '');
}
Expand Down
9 changes: 6 additions & 3 deletions question/format/xhtml/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ protected function writequestion($question) {
break;
case 'shortanswer':
$expout .= "<ul class=\"shortanswer\">\n";
$expout .= " <li><input name=\"quest_$id\" type=\"text\" /></li>\n";
$expout .= " <li>" . html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide'));
$expout .= " <input id=\"quest_$id\" name=\"quest_$id\" type=\"text\" /></li>\n";
$expout .= "</ul>\n";
break;
case 'numerical':
$expout .= "<ul class=\"numerical\">\n";
$expout .= " <li><input name=\"quest_$id\" type=\"text\" /></li>\n";
$expout .= " <li>" . html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide'));
$expout .= " <input id=\"quest_$id\" name=\"quest_$id\" type=\"text\" /></li>\n";
$expout .= "</ul>\n";
break;
case 'match':
Expand All @@ -114,7 +116,8 @@ protected function writequestion($question) {
shuffle( $ans_list ); // random display order

// build drop down for answers
$dropdown = "<select name=\"quest_$id\">\n";
$dropdown = html_writer::label(get_string('selectansweroption'), 'quest_'.$id, false, array('class' => 'accesshide'));
$dropdown .= "<select id=\"quest_$id\" name=\"quest_$id\">\n";
foreach($ans_list as $ans) {
$dropdown .= "<option value=\"" . s($ans) . "\">" . s($ans) . "</option>\n";
}
Expand Down
1 change: 1 addition & 0 deletions question/format/xhtml/lang/en/qformat_xhtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
$string['pluginname'] = 'XHTML format';
$string['pluginname_help'] = 'XHTML format enables all questions in the category to be exported to a single page of strict XHTML for possible use in another application.';
$string['pluginname_link'] = 'qformat/xhtml';
$string['selectansweroption'] = 'Select answer option';
2 changes: 2 additions & 0 deletions question/type/calculated/lang/en/qtype_calculated.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
$string['decimals'] = 'with {$a}';
$string['deleteitem'] = 'Delete item';
$string['deletelastitem'] = 'Delete last item';
$string['distributionoption'] = 'Select distribution option';
$string['editdatasets'] = 'Edit the wildcards datasets';
$string['editdatasets_help'] = 'Wildcard values may be created by entering a number in each wild card field then clicking the add button. To automatically generate 10 or more values, select the number of values required before clicking the add button. A uniform distribution means any value between the limits is equally likely to be generated; a loguniform distribution means that values towards the lower limit are more likely.';
$string['editdatasets_link'] = 'question/type/calculated';
Expand Down Expand Up @@ -79,6 +80,7 @@
$string['keptlocal2'] = 'a file from the same question private set of files as before';
$string['keptlocal3'] = 'a link from the same question private set of links as before';
$string['lastitem(s)'] = 'last items(s)';
$string['lengthoption'] = 'Select length option';
$string['loguniform'] = 'Loguniform';
$string['loguniformbit'] = 'digits, from a loguniform distribution';
$string['makecopynextpage'] = 'Next page (new question)';
Expand Down
6 changes: 4 additions & 2 deletions question/type/calculated/questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,11 +751,13 @@ public function custom_generator_tools($datasetdef) {
? 'decimals'
: 'significantfigures'), 'qtype_calculated', $i);
}
$menu1 = html_writer::select($lengthoptions, 'calclength[]', $regs[4], null);
$menu1 = html_writer::label(get_string('lengthoption', 'qtype_calculated'), 'menucalclength', false, array('class' => 'accesshide'));
$menu1 .= html_writer::select($lengthoptions, 'calclength[]', $regs[4], null);

$options = array('uniform' => get_string('uniformbit', 'qtype_calculated'),
'loguniform' => get_string('loguniformbit', 'qtype_calculated'));
$menu2 = html_writer::select($options, 'calcdistribution[]', $regs[1], null);
$menu2 = html_writer::label(get_string('distributionoption', 'qtype_calculated'), 'menucalcdistribution', false, array('class' => 'accesshide'));
$menu2 .= html_writer::select($options, 'calcdistribution[]', $regs[1], null);
return '<input type="submit" onclick="'
. "getElementById('addform').regenerateddefid.value='$defid'; return true;"
.'" value="'. get_string('generatevalue', 'qtype_calculated') . '"/><br/>'
Expand Down
1 change: 1 addition & 0 deletions question/type/essay/lang/en/qtype_essay.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@
$string['pluginnamesummary'] = 'Allows a response of a few sentences or paragraphs. This must then be graded manually.';
$string['responsefieldlines'] = 'Input box size';
$string['responseformat'] = 'Response format';
$string['selectanswerformat'] = 'Select answer format';
3 changes: 2 additions & 1 deletion question/type/essay/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,13 @@ public function response_area_input($name, $qa, $step, $lines, $context) {
array('id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60)));

$output .= html_writer::start_tag('div');
if (count($formats == 1)) {
if (count($formats) == 1) {
reset($formats);
$output .= html_writer::empty_tag('input', array('type' => 'hidden',
'name' => $inputname . 'format', 'value' => key($formats)));

} else {
$output .= html_writer::label(get_string('selectanswerformat'), 'menu' . $inputname . 'format', false, array("class" => 'accesshide'));
$output .= html_writer::select($formats, $inputname . 'format', $responseformat, '');
}
$output .= html_writer::end_tag('div');
Expand Down
1 change: 1 addition & 0 deletions question/type/match/lang/en/qtype_match.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@
$string['pluginnameadding'] = 'Adding a Matching question';
$string['pluginnameediting'] = 'Editing a Matching question';
$string['pluginnamesummary'] = 'The answer to each of a number of sub-question must be selected from a list of possibilities.';
$string['selectananswer'] = 'Select an answer';
1 change: 1 addition & 0 deletions question/type/match/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function formulation_and_controls(question_attempt $qa,
}

$result .= html_writer::tag('td',
html_writer::label(get_string('selectananswer', 'qtype_match'), 'menu' . $qa->get_qt_field_name('sub' . $key), false, array('class' => 'accesshide')) .
html_writer::select($choices, $qa->get_qt_field_name('sub' . $key), $selected,
array('0' => 'choose'), array('disabled' => $options->readonly)) .
' ' . $feedbackimage, array('class' => $classes));
Expand Down
6 changes: 3 additions & 3 deletions question/type/multianswer/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function subquestion(question_attempt $qa, question_display_options $opti
s($correctanswer->answer), $options);

$output = '';
$output .= html_writer::start_tag('label', array('class' => 'subq'));
$output .= html_writer::start_tag('label', array('class' => 'subq', 'for' => $inputattributes['id']));
$output .= html_writer::empty_tag('input', $inputattributes);
$output .= $feedbackimg;
$output .= $feedbackpopup;
Expand Down Expand Up @@ -274,8 +274,8 @@ public function subquestion(question_attempt $qa, question_display_options $opti
$inputattributes['class'] = $this->feedback_class($matchinganswer->fraction);
$feedbackimg = $this->feedback_image($matchinganswer->fraction);
}

$select = html_writer::select($choices, $qa->get_qt_field_name($fieldname),
$select = html_writer::label($response, $inputattributes['id'], false, array('class' => 'accesshide'));
$select .= html_writer::select($choices, $qa->get_qt_field_name($fieldname),
$response, array('' => ''), $inputattributes);

$order = $subq->get_order($qa);
Expand Down
7 changes: 5 additions & 2 deletions question/type/numerical/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public function formulation_and_controls(question_attempt $qa,
$inputattributes['size'] = round(strlen($placeholder) * 1.1);
}

$input = html_writer::empty_tag('input', $inputattributes) . $feedbackimg;
$input = html_writer::label($inputattributes['name'], $inputattributes['id'], false, array('class' => 'accesshide'));
$input .= html_writer::empty_tag('input', $inputattributes) . $feedbackimg;

if ($question->has_separate_unit_field()) {
if ($question->unitdisplay == qtype_numerical::UNITRADIO) {
Expand All @@ -98,7 +99,9 @@ public function formulation_and_controls(question_attempt $qa,
array('class' => 'unitchoices'));

} else if ($question->unitdisplay == qtype_numerical::UNITSELECT) {
$unitchoice = html_writer::select($question->ap->get_unit_options(),
$unitchoice = html_writer::label(get_string('selectunits', 'qtype_numerical'),
'menu' . $qa->get_qt_field_name('unit'), false, array('class' => 'accesshide'));
$unitchoice .= html_writer::select($question->ap->get_unit_options(),
$qa->get_qt_field_name('unit'), $selectedunit, array(''=>'choosedots'),
array('disabled' => $options->readonly));
}
Expand Down
4 changes: 2 additions & 2 deletions question/type/shortanswer/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function formulation_and_controls(question_attempt $qa,
$placeholder = $matches[0];
$inputattributes['size'] = round(strlen($placeholder) * 1.1);
}

$input = html_writer::empty_tag('input', $inputattributes) . $feedbackimg;
$input = html_writer::label($inputattributes['name'], $inputattributes['id'], false, array('class' => 'accesshide'));
$input .= html_writer::empty_tag('input', $inputattributes) . $feedbackimg;

if ($placeholder) {
$questiontext = substr_replace($questiontext, $input,
Expand Down

0 comments on commit 8369017

Please sign in to comment.