Skip to content

Commit

Permalink
Allow setting `requirement' on form elements
Browse files Browse the repository at this point in the history
It's supposed to be used as description what
kind of value an element will accept.

refs #7947
  • Loading branch information
Johannes Meyer committed Mar 6, 2015
1 parent b9811f8 commit 6cfa958
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion library/Icinga/Web/Form.php
Expand Up @@ -157,7 +157,7 @@ class Form extends Zend_Form
public static $defaultElementDecorators = array(
array('ViewHelper', array('separator' => '')),
array('Errors', array('separator' => '')),
array('Help'),
array('Help', array('placement' => 'PREPEND')),
array('Label', array('separator' => '')),
array('HtmlTag', array('tag' => 'div', 'class' => 'element'))
);
Expand Down
27 changes: 22 additions & 5 deletions library/Icinga/Web/Form/Decorator/Help.php
Expand Up @@ -76,18 +76,35 @@ protected function getView()
*/
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) {
$content = '<span id="'
$helpContent = '<span id="'
. $this->getDescriptionId()
. '" class="sr-only">'
. $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;
}
}
}

0 comments on commit 6cfa958

Please sign in to comment.