From 5485ca8a25b41beff1d943ee6c6da7ed0aa1f9d6 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 2 Sep 2014 16:48:54 +0200 Subject: [PATCH] lib: Use Zend's `Int' validator in the `Number' form element Further disabled default decorators since our form sets them. refs #5525 --- library/Icinga/Web/Form/Element/Number.php | 41 +++++++++++----------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/library/Icinga/Web/Form/Element/Number.php b/library/Icinga/Web/Form/Element/Number.php index d87a6d09f..3bfbc6406 100644 --- a/library/Icinga/Web/Form/Element/Number.php +++ b/library/Icinga/Web/Form/Element/Number.php @@ -4,38 +4,37 @@ namespace Icinga\Web\Form\Element; -use Zend_Form_Element_Xhtml; +use Zend_Form_Element; /** - * Number form element + * A number input control */ -class Number extends Zend_Form_Element_Xhtml +class Number extends Zend_Form_Element { /** - * Default form view helper to use for rendering + * Disable default decorators + * + * \Icinga\Web\Form sets default decorators for elements. + * + * @var bool + * + * @see \Icinga\Web\Form::__construct() For default element decorators. + */ + protected $_disableLoadDefaultDecorators = true; + + /** + * Form view helper to use for rendering * * @var string */ - public $helper = "formNumber"; + public $helper = 'formNumber'; /** - * Check whether $value is of type integer - * - * @param string $value The value to check - * @param mixed $context Context to use - * - * @return bool + * (non-PHPDoc) + * @see \Zend_Form_Element::init() For the method documentation. */ - public function isValid($value, $context = null) + public function init() { - if (parent::isValid($value, $context)) { - if (is_numeric($value)) { - return true; - } - - $this->addError(t('Please enter a number.')); - } - - return false; + $this->addValidator('Int'); } }