Ensure that we advance a wizard when pushing ENTER

refs #7163
This commit is contained in:
Johannes Meyer 2014-10-09 13:41:06 +02:00
parent 169a646a1a
commit f8f27e046d
3 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,64 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Form\Decorator;
use Zend_Form_Element;
use Zend_Form_Decorator_Abstract;
/**
* A decorator that will double a single element of a display group
*
* The options `condition', `double' and `attributes' can be passed to the constructor and are used to affect whether
* the doubling should take effect, which element should be doubled and which HTML attributes should be applied to the
* doubled element, respectively.
*
* `condition' must be an element's name that when it's part of the display group causes the condition to be met.
* `double' must be an element's name and must be part of the display group.
* `attributes' is just an array of key-value pairs.
*
* You can also pass `placement' to control whether the doubled element is prepended or appended.
*/
class ElementDoubler extends Zend_Form_Decorator_Abstract
{
/**
* Return the display group's elements with an additional copy of an element being added if the condition is met
*
* @param string $content The HTML rendered so far
*
* @return string
*/
public function render($content)
{
$group = $this->getElement();
if ($group->getElement($this->getOption('condition')) !== null) {
if ($this->getPlacement() === static::APPEND) {
return $content . $this->applyAttributes($group->getElement($this->getOption('double')))->render();
} else { // $this->getPlacement() === static::PREPEND
return $this->applyAttributes($group->getElement($this->getOption('double')))->render() . $content;
}
}
return $content;
}
/**
* Apply all element attributes
*
* @param Zend_Form_Element $element The element to apply the attributes to
*
* @return Zend_Form_Element
*/
protected function applyAttributes(Zend_Form_Element $element)
{
$attributes = $this->getOption('attributes');
if ($attributes !== null) {
foreach ($attributes as $name => $value) {
$element->setAttrib($name, $value);
}
}
return $element;
}
}

View File

@ -7,6 +7,7 @@ namespace Icinga\Web;
use LogicException;
use InvalidArgumentException;
use Icinga\Web\Session\SessionNamespace;
use Icinga\Web\Form\Decorator\ElementDoubler;
/**
* Container and controller for form based wizards
@ -476,6 +477,12 @@ class Wizard
array(
'decorators' => array(
'FormElements',
new ElementDoubler(array(
'double' => static::BTN_NEXT,
'condition' => static::BTN_PREV,
'placement' => ElementDoubler::PREPEND,
'attributes' => array('tabindex' => -1, 'class' => 'double')
)),
array('HtmlTag', array('tag' => 'div', 'class' => 'buttons'))
)
)

View File

@ -4,6 +4,11 @@
#setup div.buttons {
margin: 1.5em 0 0 1.8em;
.double {
position: absolute;
left: -1337px;
}
}
#setup table.requirements {