From 102621f53deaa43a240f4d8e2c94108eee18e28c Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 6 Mar 2025 08:34:03 +0000 Subject: [PATCH] MDL-84752 qtype_essay: create accessible min/max words form elements. Because of historical requirements involving fieldsets in question type forms (see 958e7671), we should use ARIA label attribute on grouped elements rather than normal labels in order to make them accessible. Co-authored-by: Jun Pataleta --- question/type/essay/edit_essay_form.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/question/type/essay/edit_essay_form.php b/question/type/essay/edit_essay_form.php index dc035ef1adc..0fe2d5a30e1 100644 --- a/question/type/essay/edit_essay_form.php +++ b/question/type/essay/edit_essay_form.php @@ -57,21 +57,24 @@ class qtype_essay_edit_form extends question_edit_form { // Create a text box that can be enabled/disabled for max/min word limits options. $wordlimitoptions = ['size' => '6', 'maxlength' => '6']; - $mingrp[] = $mform->createElement('text', 'minwordlimit', '', $wordlimitoptions); - $mform->setType('minwordlimit', PARAM_INT); + + $strminwordlimit = get_string('minwordlimit', 'qtype_essay'); $mingrp[] = $mform->createElement('checkbox', 'minwordenabled', '', get_string('enable')); $mform->setDefault('minwordenabled', 0); - $mform->addGroup($mingrp, 'mingroup', get_string('minwordlimit', 'qtype_essay'), ' ', false); + $mingrp[] = $mform->createElement('text', 'minwordlimit', '', $wordlimitoptions + ['aria-label' => $strminwordlimit]); + $mform->setType('minwordlimit', PARAM_INT); + $mform->addGroup($mingrp, 'mingroup', $strminwordlimit, ' ', false); $mform->addHelpButton('mingroup', 'minwordlimit', 'qtype_essay'); $mform->disabledIf('minwordlimit', 'minwordenabled', 'notchecked'); $mform->hideIf('mingroup', 'responserequired', 'eq', '0'); $mform->hideIf('mingroup', 'responseformat', 'eq', 'noinline'); - $maxgrp[] = $mform->createElement('text', 'maxwordlimit', '', $wordlimitoptions); - $mform->setType('maxwordlimit', PARAM_INT); + $strmaxwordlimit = get_string('maxwordlimit', 'qtype_essay'); $maxgrp[] = $mform->createElement('checkbox', 'maxwordenabled', '', get_string('enable')); $mform->setDefault('maxwordenabled', 0); - $mform->addGroup($maxgrp, 'maxgroup', get_string('maxwordlimit', 'qtype_essay'), ' ', false); + $maxgrp[] = $mform->createElement('text', 'maxwordlimit', '', $wordlimitoptions + ['aria-label' => $strmaxwordlimit]); + $mform->setType('maxwordlimit', PARAM_INT); + $mform->addGroup($maxgrp, 'maxgroup', $strmaxwordlimit, ' ', false); $mform->addHelpButton('maxgroup', 'maxwordlimit', 'qtype_essay'); $mform->disabledIf('maxwordlimit', 'maxwordenabled', 'notchecked'); $mform->hideIf('maxgroup', 'responserequired', 'eq', '0');