Allow setting `requirement' on form elements
It's supposed to be used as description what kind of value an element will accept. refs #7947
This commit is contained in:
parent
b9811f8590
commit
6cfa958bb8
|
@ -157,7 +157,7 @@ class Form extends Zend_Form
|
||||||
public static $defaultElementDecorators = array(
|
public static $defaultElementDecorators = array(
|
||||||
array('ViewHelper', array('separator' => '')),
|
array('ViewHelper', array('separator' => '')),
|
||||||
array('Errors', array('separator' => '')),
|
array('Errors', array('separator' => '')),
|
||||||
array('Help'),
|
array('Help', array('placement' => 'PREPEND')),
|
||||||
array('Label', array('separator' => '')),
|
array('Label', array('separator' => '')),
|
||||||
array('HtmlTag', array('tag' => 'div', 'class' => 'element'))
|
array('HtmlTag', array('tag' => 'div', 'class' => 'element'))
|
||||||
);
|
);
|
||||||
|
|
|
@ -76,18 +76,35 @@ class Help extends Zend_Form_Decorator_Abstract
|
||||||
*/
|
*/
|
||||||
public function render($content = '')
|
public function render($content = '')
|
||||||
{
|
{
|
||||||
if ($content && ($description = $this->getElement()->getDescription()) !== null) {
|
$element = $this->getElement();
|
||||||
|
$description = $element->getDescription();
|
||||||
|
$requirement = $element->getAttrib('requirement');
|
||||||
|
unset($element->requirement);
|
||||||
|
|
||||||
|
$helpContent = '';
|
||||||
|
if ($description || $requirement) {
|
||||||
if ($this->accessible) {
|
if ($this->accessible) {
|
||||||
$content = '<span id="'
|
$helpContent = '<span id="'
|
||||||
. $this->getDescriptionId()
|
. $this->getDescriptionId()
|
||||||
. '" class="sr-only">'
|
. '" class="sr-only">'
|
||||||
. $description
|
. $description
|
||||||
. '</span>' . $content;
|
. ($description && $requirement ? ' ' : '')
|
||||||
|
. $requirement
|
||||||
|
. '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $this->getView()->icon('help', $description, array('aria-hidden' => 'true')) . $content;
|
$helpContent = $this->getView()->icon(
|
||||||
|
'help',
|
||||||
|
$description . ($description && $requirement ? ' ' : '') . $requirement,
|
||||||
|
array('aria-hidden' => $this->accessible ? 'true' : 'false')
|
||||||
|
) . $helpContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $content;
|
switch ($this->getPlacement()) {
|
||||||
|
case self::APPEND:
|
||||||
|
return $content . $helpContent;
|
||||||
|
case self::PREPEND:
|
||||||
|
return $helpContent . $content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue