Having run a few tests the project quick navigation currently does not provide a label for the select field. This is an accessibility issue which is very easy to fix by adding the '#title' => t('Projects') entry to the select section of the form fields as below. Can this be included in future version???
function project_quick_navigate_form() {
$uris = NULL;
$projects = array_merge(array(0 => t('
')), project_projects_select_options($uris, FALSE, 'node/'));
$form = array();
$form['project_goto'] = array(
'#type' => 'select',
'#default_value' => '0',
'#title' => t('Projects'),
'#options' => $projects
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Go')
);
return $form;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 293148_project_navigate_block_accessibility.6.patch | 1.34 KB | dww |
| #1 | 293148_project_quick_navigate_accessibility_1.patch | 730 bytes | aclight |
Comments
Comment #1
aclight commentedI've attached a patch that does what you want. However, I don't think we should do this.
I don't see that having a title next to/above the select box adds anything, and it just takes up more space. Furthermore, none of the other blocks on my test site that are forms (eg. the core search block, the project search block, the devel switch user block) have a title for the form element, so this problem is not unique to this particular block.
What exactly is the problem with accessibility if the form element itself does not have a title? Are there any ways we can add a title that isn't displayed by default (without jumping through FAPI hoops)?
Alternately, you should be able to write a simple module that implements hook_form_alter() on your site and add a title to the form element yourself, if you're worried primarily about your own site being accessible.
Comment #2
wsherliker commentedThanks for your help here. I have looked into the other forms such as the core search and found that the solution lies in using the title attribute of the select field to describe its function instead of a separate label. Therefore the following with the additional #attributes entry 'title' => 'Select a project to view' solves the accessibility problems without adding the untidy label to the output. Hope this helps:
function project_quick_navigate_form() {
$uris = NULL;
$projects = array_merge(array(0 => t('
')), project_projects_select_options($uris, FALSE, 'node/'));
$form = array();
$form['project_goto'] = array(
'#type' => 'select',
'#default_value' => '0',
'#attributes' => array('title' => 'Select a project to view', 'onchange' => 'this.form.submit();')m
#title' => t('Projects'),
'#options' => $projects
);
$form['submit'] = array(
'#type' => 'submit',
'#id' => 'project-submit',
'#value' => t('Go')
);
return $form;
}
Comment #3
wsherliker commentedCorrection, ignore previous code as it is missing a few commas, the original label and some quotes, this is the corrected version:
function project_quick_navigate_form() {
$uris = NULL;
$projects = array_merge(array(0 => t('
')), project_projects_select_options($uris, FALSE, 'node/'));
$form = array();
$form['project_goto'] = array(
'#type' => 'select',
'#default_value' => '0',
'#attributes' => array('title' => 'Select a project to view', 'onchange' => 'this.form.submit();'),
'#options' => $projects
);
$form['submit'] = array(
'#type' => 'submit',
'#id' => 'project-submit',
'#value' => t('Go')
);
return $form;
}
Comment #4
dwwSure, that makes sense. Thanks for the report.
Comment #5
aclight commented@wsherliker: Thanks for clarifying. It would be great if you could provide a patch for this as well, since you've already written the code. See http://drupal.org/patch/create and http://drupal.org/node/128209 for information on how to do this. I highly recommend using the cvs diff version as it's much easier to roll patches that way, assuming you've checked out the modules instead of downloading the tarballs. Issues with patches attached tend to get fixed faster since it's easier for us to apply a patch than it is to open up the appropriate file, find the lines that need to be modified, and make the changes. If you've never written a patch before this would be a really easy one and a good way to get started!
Comment #6
dwwSeems wsherliker was never going to post a patch, so I did so. I wrapped the message in t(), and removed the onchange stuff which I wasn't sure I liked (and had nothing to do with accessibility). I fixed a slightly related usability bug which is that there was no validation to check you had selected a project, it just submitted the form and nothing happened. Now, if you leave the default value and click "Go", it gives you a form error.
Comment #7
dwwhunmonk gave this the thumbs-up. Committed to HEAD and DRUPAL-5.