Add an asterisk suffix to a form element's label if its required

The screen reader part "(required)" is not being considered with this
commit as most screen readers do not need this due to the ARIA and
HTML5 property.

resolves #7934
This commit is contained in:
Johannes Meyer 2015-02-26 16:05:13 +01:00
parent 4351603243
commit 0111fdf78e
1 changed files with 5 additions and 0 deletions

View File

@ -583,6 +583,11 @@ class Form extends Zend_Form
if ($element->isRequired() && strpos(strtolower($element->getType()), 'checkbox') === false) {
$element->setAttrib('aria-required', 'true'); // ARIA
$element->setAttrib('required', ''); // HTML5
if (($label = $element->getDecorator('label')) !== false) {
$element->setLabel($this->getView()->escape($element->getLabel()));
$label->setOption('escape', false);
$label->setOption('requiredSuffix', ' <span aria-hidden="true">*</span>');
}
}
return $element;