Skip to content

Commit b2ee5bd

Browse files
emanoylovEmanoil Manoylov
andauthored
Questionnaire/Accessibility: Radio buttons & Yes/No missing group label (#511)
Co-authored-by: Emanoil Manoylov <[email protected]>
1 parent e8607f8 commit b2ee5bd

File tree

6 files changed

+85
-38
lines changed

6 files changed

+85
-38
lines changed

classes/question/radio.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ protected function question_survey_display($response, $dependants=[], $blankques
122122
}
123123
$contents = questionnaire_choice_values($choice->content);
124124
$radio->label = $value.format_text($contents->text, FORMAT_HTML, ['noclean' => true]).$contents->image;
125+
if (!empty($this->qlegend)) {
126+
$radio->alabel = strip_tags("{$this->qlegend} {$radio->label}");
127+
}
125128
} else { // Radio button with associated !other text field.
126129
$othertext = $choice->other_choice_display();
127130
$cname = choice::id_other_choice_name($id);
@@ -143,6 +146,10 @@ protected function question_survey_display($response, $dependants=[], $blankques
143146
$radio->ovalue = format_string(stripslashes($odata));
144147
}
145148
$radio->olabel = 'Text for '.format_text($othertext, FORMAT_HTML, ['noclean' => true]);
149+
if (!empty($this->qlegend)) {
150+
$radio->alabel = strip_tags("{$this->qlegend} {$radio->label}");
151+
$radio->aolabel = strip_tags("{$this->qlegend} {$radio->olabel}");
152+
}
146153
}
147154
$choicetags->qelements[] = (object)['choice' => $radio];
148155
}
@@ -164,6 +171,9 @@ protected function question_survey_display($response, $dependants=[], $blankques
164171
}
165172
$content = get_string('noanswer', 'questionnaire');
166173
$radio->label = format_text($content, FORMAT_HTML, ['noclean' => true]);
174+
if (!empty($this->qlegend)) {
175+
$radio->alabel = strip_tags("{$this->qlegend} {$radio->label}");
176+
}
167177

168178
$choicetags->qelements[] = (object)['choice' => $radio];
169179
}
@@ -213,6 +223,9 @@ protected function response_survey_display($response) {
213223
} else {
214224
$chobj->content = ($choice->content === '' ? $id : format_text($choice->content, FORMAT_HTML, ['noclean' => true]));
215225
}
226+
if (!empty($this->qlegend)) {
227+
$chobj->alabel = strip_tags("{$this->qlegend} {$chobj->content}");
228+
}
216229
$resptags->choices[] = $chobj;
217230
}
218231

classes/question/yesno.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ protected function question_survey_display($response, $dependants=[], $blankques
154154
if ($blankquestionnaire) {
155155
$option->disabled = true;
156156
}
157+
if (!empty($this->qlegend)) {
158+
$option->alabel = strip_tags("{$this->qlegend} {$option->label}");
159+
}
157160
$choicetags->qelements->choice[] = $option;
158161
}
159162
// CONTRIB-846.
@@ -169,6 +172,9 @@ protected function question_survey_display($response, $dependants=[], $blankques
169172
if (!$ischecked && !$blankquestionnaire) {
170173
$option->checked = true;
171174
}
175+
if (!empty($this->qlegend)) {
176+
$option->alabel = strip_tags("{$this->qlegend} {$option->label}");
177+
}
172178
$choicetags->qelements->choice[] = $option;
173179
}
174180
// End CONTRIB-846.
@@ -201,6 +207,10 @@ protected function response_survey_display($response) {
201207
if ($answer->value == 'n') {
202208
$resptags->noselected = 1;
203209
}
210+
if (!empty($this->qlegend)) {
211+
$resptags->alabelyes = strip_tags("{$this->qlegend} {$resptags->stryes}");
212+
$resptags->alabelno = strip_tags("{$this->qlegend} {$resptags->strno}");
213+
}
204214

205215
return $resptags;
206216
}

templates/question_radio.mustache

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"checked": "",
4040
"disabled": 1,
4141
"onclick": 1,
42-
"label": "Choice question label"
42+
"label": "Choice label",
43+
"alabel": "Some question Choice label"
4344
}
4445
},
4546
{
@@ -50,9 +51,11 @@
5051
"name": "choiceid2",
5152
"checked": "1",
5253
"onclick": 1,
53-
"label": "Choice question label",
54+
"label": "Choice label",
55+
"alabel": "Some question Choice label",
5456
"oid": "choiceid2_7",
55-
"olabel": "Choice question other label",
57+
"olabel": "Choice other label",
58+
"aolabel": "Some question Choice other label",
5659
"oname": "Other",
5760
"ovalue": "another choice"
5861
}
@@ -62,15 +65,19 @@
6265
}}
6366
<!-- Begin HTML generated from question_radio template. -->
6467
{{#qelements}}
65-
{{#choice}}
66-
{{#choice.horizontal}}<span style="white-space:nowrap;">{{/choice.horizontal}}
67-
<input id="{{choice.id}}" value="{{choice.value}}" name="{{choice.name}}" type="radio" {{#choice.checked}}checked="checked"{{/choice.checked}} {{#choice.disabled}}disabled="disabled"{{/choice.disabled}} {{#choice.onclick}}onclick="{{choice.onclick}}"{{/choice.onclick}}/>
68-
<label for="{{choice.id}}">{{{choice.label}}}</label>
69-
{{#choice.oname}}
70-
<input size="25" name="{{choice.oname}}" id="{{choice.oid}}" onclick="other_check(name)" value="{{choice.ovalue}}" type="text" /><label for="{{choice.oid}}" class="accesshide">{{{choice.olabel}}}</label>&nbsp;
71-
{{/choice.oname}}
72-
{{#choice.horizontal}}</span>{{/choice.horizontal}}
73-
{{^choice.horizontal}}<br />{{/choice.horizontal}}
74-
{{/choice}}
68+
{{#choice}}
69+
{{#choice.horizontal}}<span style="white-space:nowrap;">{{/choice.horizontal}}
70+
<input id="{{choice.id}}" value="{{choice.value}}" name="{{choice.name}}" type="radio"
71+
{{#choice.checked}}checked="checked"{{/choice.checked}} {{#choice.disabled}}disabled="disabled"{{/choice.disabled}}
72+
{{#choice.onclick}}onclick="{{choice.onclick}}"{{/choice.onclick}} aria-label="{{alabel}}"/>
73+
<label for="{{choice.id}}">{{{choice.label}}}</label>
74+
{{#choice.oname}}
75+
<input size="25" name="{{choice.oname}}" id="{{choice.oid}}" onclick="other_check(name)"
76+
value="{{choice.ovalue}}" type="text" aria-label="{{aolabel}}"/>
77+
<label for="{{choice.oid}}" class="accesshide">{{{choice.olabel}}}</label>&nbsp;
78+
{{/choice.oname}}
79+
{{#choice.horizontal}}</span>{{/choice.horizontal}}
80+
{{^choice.horizontal}}<br/>{{/choice.horizontal}}
81+
{{/choice}}
7582
{{/qelements}}
7683
<!-- End HTML generated from question_radio template. -->

templates/question_yesno.mustache

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"checked": 1,
3939
"disabled": "",
4040
"onclick": "dosomething()",
41-
"label": "Yes"
41+
"label": "Yes",
42+
"alabel": "Some question Yes"
4243
},
4344
{
4445
"id": "choice2",
@@ -47,17 +48,20 @@
4748
"checked": 0,
4849
"disabled": "",
4950
"onclick": "dosomething()",
50-
"label": "No"
51+
"label": "No",
52+
"alabel": "Some question No"
5153
}
5254
]
5355
}
5456
}
5557
}}
5658
<!-- Begin HTML generated from question_yesno template. -->
5759
{{#qelements}}
58-
{{#choice}}
59-
<input id="{{id}}" value="{{value}}" name="{{name}}" type="radio" {{#checked}}checked="checked"{{/checked}} {{#disabled}}disabled="disabled"{{/disabled}} {{#onclick}}onclick="{{onclick}}"{{/onclick}}/>
60-
<label for="{{id}}">{{{label}}}</label>
61-
{{/choice}}
60+
{{#choice}}
61+
<input id="{{id}}" value="{{value}}" name="{{name}}" type="radio"
62+
{{#checked}}checked="checked"{{/checked}} {{#disabled}}disabled="disabled"{{/disabled}} {{#onclick}}onclick="{{onclick}}"{{/onclick}}
63+
aria-label="{{alabel}}"/>
64+
<label for="{{id}}">{{{label}}}</label>
65+
{{/choice}}
6266
{{/qelements}}
6367
<!-- End HTML generated from question_yesno template. -->

templates/response_radio.mustache

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,23 @@
4848
}}
4949
<!-- Begin HTML generated from response_radio template. -->
5050
<div class="questionnaire_response questionnaire_radio">
51-
{{#choices}}
52-
{{#horizontal}}<span style="white-space:nowrap;">{{/horizontal}}
53-
{{#selected}}
54-
<span class="selected">
55-
{{^pdf}}<input type="radio" name="{{name}}" checked="checked" disabled="disabled" />{{/pdf}}
56-
{{#pdf}}&#10003;{{/pdf}} {{{content}}}{{#othercontent}} <span class="response text">{{.}}</span>{{/othercontent}}
51+
{{#choices}}
52+
{{#horizontal}}<span style="white-space:nowrap;">{{/horizontal}}
53+
{{#selected}}
54+
<span class="selected">
55+
{{^pdf}}
56+
<input type="radio" name="{{name}}" checked="checked" disabled="disabled"
57+
aria-label="{{alabel}}"/>{{/pdf}}
58+
{{#pdf}}&#10003;{{/pdf}} {{{content}}}{{#othercontent}} <span class="response text">{{.}}</span>{{/othercontent}}
5759
</span>
58-
{{/selected}}
59-
{{^selected}}
60-
<span class="unselected"{{#pdf}} color="gray"{{/pdf}}>{{^pdf}}<input type="radio" name="{{name}}" disabled="disabled" />{{/pdf}}
61-
{{{content}}}</span>&nbsp;
62-
{{/selected}}
63-
{{#horizontal}}</span>{{/horizontal}}
64-
{{^horizontal}}<br />{{/horizontal}}
65-
{{/choices}}
60+
{{/selected}}
61+
{{^selected}}
62+
<span class="unselected"{{#pdf}} color="gray"{{/pdf}}>{{^pdf}}
63+
<input type="radio" name="{{name}}" disabled="disabled" aria-label="{{alabel}}"/>{{/pdf}}
64+
{{{content}}}</span>&nbsp;
65+
{{/selected}}
66+
{{#horizontal}}</span>{{/horizontal}}
67+
{{^horizontal}}<br/>{{/horizontal}}
68+
{{/choices}}
6669
</div>
6770
<!-- End HTML generated from response_radio template. -->

templates/response_yesno.mustache

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,32 @@
3434
"stryes": "Yes",
3535
"noselected": 0,
3636
"noname": "id4102n",
37-
"strno": "No"
37+
"strno": "No",
38+
"alabelyes": "Some question Yes",
39+
"alabelno": "Some question No"
3840
}
3941
}}
4042
<!-- Begin HTML generated from response_yesno template. -->
4143
<div class="questionnaire_response questionnaire_yesno">
4244
{{#yesselected}}
43-
{{#pdf}}&#10003;{{/pdf}}<span class="selected">{{^pdf}}<input type="radio" name="{{yesname}}" checked="checked" disabled="disabled"/>{{/pdf}} {{{stryes}}}</span>
45+
{{#pdf}}&#10003;{{/pdf}}<span class="selected">{{^pdf}}
46+
<input type="radio" name="{{yesname}}" checked="checked" disabled="disabled"
47+
aria-label="{{alabelyes}}"/>{{/pdf}} {{{stryes}}}</span>
4448
{{/yesselected}}
4549
{{^yesselected}}
46-
<span class="unselected"{{#pdf}} color="gray"{{/pdf}}>{{^pdf}}<input type="radio" name="{{yesname}}" disabled="disabled"/>{{/pdf}} {{{stryes}}}</span>
50+
<span class="unselected"{{#pdf}} color="gray"{{/pdf}}>{{^pdf}}
51+
<input type="radio" name="{{yesname}}" disabled="disabled"
52+
aria-label="{{alabelyes}}"/>{{/pdf}} {{{stryes}}}</span>
4753
{{/yesselected}}
4854
{{#noselected}}
49-
{{#pdf}}&nbsp; &#10003;{{/pdf}}<span class="selected">{{^pdf}}<input type="radio" name="{{noname}}" checked="checked" disabled="disabled"/>{{/pdf}} {{{strno}}}</span>
55+
{{#pdf}}&nbsp; &#10003;{{/pdf}}<span class="selected">{{^pdf}}
56+
<input type="radio" name="{{noname}}" checked="checked" disabled="disabled"
57+
aria-label="{{alabelno}}"/>{{/pdf}} {{{strno}}}</span>
5058
{{/noselected}}
5159
{{^noselected}}
52-
<span class="unselected"{{#pdf}} color="gray"{{/pdf}}>{{^pdf}}<input type="radio" name="{{noname}}" disabled="disabled"/>{{/pdf}} {{{strno}}}</span>
60+
<span class="unselected"{{#pdf}} color="gray"{{/pdf}}>{{^pdf}}
61+
<input type="radio" name="{{noname}}" disabled="disabled"
62+
aria-label="{{alabelno}}"/>{{/pdf}} {{{strno}}}</span>
5363
{{/noselected}}
5464
</div>
5565
<!-- End HTML generated from response_yesno template. -->

0 commit comments

Comments
 (0)