From 32bd11cb395640c8a0456766f72074171349cbe8 Mon Sep 17 00:00:00 2001 From: Brian Barnes Date: Thu, 9 Apr 2015 11:12:16 +1200 Subject: [PATCH] MDL-49628 general: improved accessibility of single selects --- badges/award.php | 6 ++++-- badges/criteria/award_criteria_overall.php | 11 +++-------- badges/renderer.php | 23 +++++++++++----------- lib/outputrenderers.php | 10 +++++++++- mod/data/field.php | 4 ++-- mod/wiki/renderer.php | 9 ++++++--- user/index.php | 4 ++-- user/profile/index.php | 2 +- 8 files changed, 39 insertions(+), 30 deletions(-) diff --git a/badges/award.php b/badges/award.php index f60bf39c876..e80fa9228ce 100644 --- a/badges/award.php +++ b/badges/award.php @@ -110,14 +110,16 @@ if (count($acceptedroles) > 1) { if (!$role) { $pageurl = new moodle_url('/badges/award.php', array('id' => $badgeid)); echo $OUTPUT->header(); - echo $OUTPUT->box(get_string('selectaward', 'badges') . $OUTPUT->single_select(new moodle_url($pageurl), 'role', $select)); + echo $OUTPUT->box($OUTPUT->single_select(new moodle_url($pageurl), 'role', $select, '', array('' => 'choosedots'), + null, array('label' => get_string('selectaward', 'badges')))); echo $OUTPUT->footer(); die(); } else { $pageurl = new moodle_url('/badges/award.php', array('id' => $badgeid)); $issuerrole = new stdClass(); $issuerrole->roleid = $role; - $roleselect = get_string('selectaward', 'badges') . $OUTPUT->single_select(new moodle_url($pageurl), 'role', $select, $role, null); + $roleselect = $OUTPUT->single_select(new moodle_url($pageurl), 'role', $select, $role, null, null, + array('label' => get_string('selectaward', 'badges'))); } } else { echo $OUTPUT->header(); diff --git a/badges/criteria/award_criteria_overall.php b/badges/criteria/award_criteria_overall.php index 7d6aad80e77..3b518998d86 100644 --- a/badges/criteria/award_criteria_overall.php +++ b/badges/criteria/award_criteria_overall.php @@ -67,14 +67,9 @@ class award_criteria_overall extends award_criteria { echo $OUTPUT->box($editaction, array('criteria-header')); $url = new moodle_url('criteria.php', array('id' => $data->id, 'sesskey' => sesskey())); - $table = new html_table(); - $table->attributes = array('class' => 'clearfix'); - $table->colclasses = array('', 'activatebadge'); - $table->data[] = array( - $OUTPUT->single_select($url, 'update', $agg, $data->get_aggregation_method($this->criteriatype), null), - get_string('overallcrit', 'badges') - ); - echo html_writer::table($table); + echo $OUTPUT->single_select($url, 'update', $agg, $data->get_aggregation_method($this->criteriatype), + null, null, array('aria-describedby' => 'overall')); + echo html_writer::span(get_string('overallcrit', 'badges'), '', array('id' => 'overall')); } else { echo $OUTPUT->box(get_string('criteria_descr_' . $this->criteriatype, 'badges', core_text::strtoupper($agg[$data->get_aggregation_method()])), 'clearfix'); diff --git a/badges/renderer.php b/badges/renderer.php index d4fad08aec0..7bbefa67974 100644 --- a/badges/renderer.php +++ b/badges/renderer.php @@ -783,11 +783,7 @@ class core_badges_renderer extends plugin_renderer_base { // Prints criteria actions for badge editing. public function print_criteria_actions(badge $badge) { - $table = new html_table(); - $table->attributes = array('class' => 'boxaligncenter', 'id' => 'badgeactions'); - $table->colclasses = array('activatebadge'); - - $actions = array(); + $output = ''; if (!$badge->is_active() && !$badge->is_locked()) { $accepted = $badge->get_accepted_criteria(); $potential = array_diff($accepted, array_keys($badge->criteria)); @@ -798,16 +794,21 @@ class core_badges_renderer extends plugin_renderer_base { $select[$p] = get_string('criteria_' . $p, 'badges'); } } - $actions[] = get_string('addbadgecriteria', 'badges'); - $actions[] = $this->output->single_select(new moodle_url('/badges/criteria_settings.php', - array('badgeid' => $badge->id, 'add' => true)), 'type', $select); + $output .= $this->output->single_select( + new moodle_url('/badges/criteria_settings.php', array('badgeid' => $badge->id, 'add' => true)), + 'type', + $select, + '', + array('' => 'choosedots'), + null, + array('label' => get_string('addbadgecriteria', 'badges')) + ); } else { - $actions[] = $this->output->box(get_string('nothingtoadd', 'badges'), 'clearfix'); + $output .= $this->output->box(get_string('nothingtoadd', 'badges'), 'clearfix'); } } - $table->data[] = $actions; - return html_writer::table($table); + return $output; } // Renders a table with users who have earned the badge. diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 89b24233778..8945817a86e 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1901,14 +1901,22 @@ class core_renderer extends renderer_base { * @param string $selected selected element * @param array $nothing * @param string $formid + * @param array $attributes other attributes for the single select * @return string HTML fragment */ - public function single_select($url, $name, array $options, $selected = '', $nothing = array('' => 'choosedots'), $formid = null) { + public function single_select($url, $name, array $options, $selected = '', + $nothing = array('' => 'choosedots'), $formid = null, $attributes = array()) { if (!($url instanceof moodle_url)) { $url = new moodle_url($url); } $select = new single_select($url, $name, $options, $selected, $nothing, $formid); + if (array_key_exists('label', $attributes)) { + $select->set_label($attributes['label']); + unset($attributes['label']); + } + $select->attributes = $attributes; + return $this->render($select); } diff --git a/mod/data/field.php b/mod/data/field.php index 77e3a29eafa..fdf2e87a28e 100644 --- a/mod/data/field.php +++ b/mod/data/field.php @@ -310,9 +310,9 @@ if (($mode == 'new') && (!empty($newtype)) && confirm_sesskey()) { /// echo '
'; - echo ''; $popupurl = $CFG->wwwroot.'/mod/data/field.php?d='.$data->id.'&mode=new&sesskey='. sesskey(); - echo $OUTPUT->single_select(new moodle_url($popupurl), 'newtype', $menufield, null, array(''=>'choosedots'), 'fieldform'); + echo $OUTPUT->single_select(new moodle_url($popupurl), 'newtype', $menufield, null, array('' => 'choosedots'), + 'fieldform', array('label' => get_string('newfield', 'data') . $OUTPUT->help_icon('newfield', 'data'))); echo '
'; echo '
'; diff --git a/mod/wiki/renderer.php b/mod/wiki/renderer.php index 0e34a3d468a..967c457a2ca 100644 --- a/mod/wiki/renderer.php +++ b/mod/wiki/renderer.php @@ -349,7 +349,8 @@ class mod_wiki_renderer extends plugin_renderer_base { echo $this->output->container_start('wiki_right'); $name = 'uid'; $selected = $subwiki->userid; - echo $this->output->single_select($baseurl, $name, $options, $selected, null); + echo $this->output->single_select($baseurl, $name, $options, $selected, null, null, + array('label' => get_string('user') . ':')); echo $this->output->container_end(); } return; @@ -398,7 +399,8 @@ class mod_wiki_renderer extends plugin_renderer_base { echo $this->output->container_start('wiki_right'); $name = 'groupanduser'; $selected = $subwiki->groupid . '-' . $subwiki->userid; - echo $this->output->single_select($baseurl, $name, $options, $selected, null); + echo $this->output->single_select($baseurl, $name, $options, $selected, null, null, + array('label' => get_string('user') . ':')); echo $this->output->container_end(); return; @@ -435,7 +437,8 @@ class mod_wiki_renderer extends plugin_renderer_base { echo $this->output->container_start('wiki_right'); $name = 'groupanduser'; $selected = $subwiki->groupid . '-' . $subwiki->userid; - echo $this->output->single_select($baseurl, $name, $options, $selected, null); + echo $this->output->single_select($baseurl, $name, $options, $selected, null, null, + array('label' => get_string('user') . ':')); echo $this->output->container_end(); return; diff --git a/user/index.php b/user/index.php index c1adf8904b0..f6b3f9eb012 100644 --- a/user/index.php +++ b/user/index.php @@ -497,8 +497,8 @@ $userlist = $DB->get_recordset_sql("$select $from $where $sort", $params, $table // If there are multiple Roles in the course, then show a drop down menu for switching. if (count($rolenames) > 1) { echo '
'; - echo ''; - echo $OUTPUT->single_select($rolenamesurl, 'roleid', $rolenames, $roleid, null, 'rolesform'); + echo $OUTPUT->single_select($rolenamesurl, 'roleid', $rolenames, $roleid, null, + 'rolesform', array('label' => get_string('currentrole', 'role'))); echo '
'; } else if (count($rolenames) == 1) { diff --git a/user/profile/index.php b/user/profile/index.php index 6bb4be3f55c..131c08f49b5 100644 --- a/user/profile/index.php +++ b/user/profile/index.php @@ -153,7 +153,7 @@ echo '
'; // Create a new field link. $options = profile_list_datatypes(); $popupurl = new moodle_url('/user/profile/index.php?id=0&action=editfield'); -echo $OUTPUT->single_select($popupurl, 'datatype', $options, '', array('' => $strcreatefield), 'newfieldform'); +echo $OUTPUT->single_select($popupurl, 'datatype', $options, '', null, 'newfieldform', array('label' => $strcreatefield)); // Add a div with a class so themers can hide, style or reposition the text. html_writer::start_tag('div', array('class' => 'adminuseractionhint'));