Skip to content

Commit

Permalink
Add the FormErrors decorator as default decorator for forms
Browse files Browse the repository at this point in the history
This allows us to use Zend_Form::addError() to show error messages for
the entire form context.

refs #5525
  • Loading branch information
Johannes Meyer committed Sep 2, 2014
1 parent 338f549 commit 539ab91
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion library/Icinga/Web/Form.php
Expand Up @@ -99,6 +99,7 @@ public function __construct($options = null)
if ($this->onSuccess !== null && false === is_callable($this->onSuccess)) {
throw new LogicException('The option `onSuccess\' is not callable');
}

if (! isset($options['elementDecorators'])) {
$options['elementDecorators'] = array(
'ViewHelper',
Expand All @@ -108,6 +109,7 @@ public function __construct($options = null)
array('HtmlTag', array('tag' => 'div'))
);
}

parent::__construct($options);
}

Expand Down Expand Up @@ -372,6 +374,7 @@ public function createElement($type, $name, $options = null)
if (is_array($options) && ! isset($options['disableLoadDefaultDecorators'])) {
$options['disableLoadDefaultDecorators'] = true;
}

$el = parent::createElement($type, $name, $options);
if ($el && $el->getAttrib('autosubmit')) {
$el->addDecorator(new NoScriptApply()); // Non-JS environments
Expand All @@ -386,6 +389,7 @@ public function createElement($type, $name, $options = null)
$el->setAttrib('class', $class); // JS environments
unset($el->autosubmit);
}

return $el;
}

Expand Down Expand Up @@ -555,6 +559,7 @@ public function loadDefaultDecorators()
if ($this->loadDefaultDecoratorsIsDisabled()) {
return $this;
}

$decorators = $this->getDecorators();
if (empty($decorators)) {
if ($this->viewScript) {
Expand All @@ -563,11 +568,13 @@ public function loadDefaultDecorators()
'form' => $this
));
} else {
$this
$this->addDecorator('FormErrors', array('onlyCustomFormErrors' => true))
->addDecorator('FormElements')
//->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
->addDecorator('Form');
}
}

return $this;
}

Expand Down

0 comments on commit 539ab91

Please sign in to comment.