3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Form\Element
;
12 use Zend\Form\Element
;
13 use Zend\I18n\Validator\
Float as NumberValidator
;
14 use Zend\InputFilter\InputProviderInterface
;
15 use Zend\Validator\GreaterThan
as GreaterThanValidator
;
16 use Zend\Validator\LessThan
as LessThanValidator
;
17 use Zend\Validator\Step
as StepValidator
;
19 class Number
extends Element
implements InputProviderInterface
26 protected $attributes = array(
33 protected $validators;
38 * @return \Zend\Validator\ValidatorInterface[]
40 protected function getValidators()
42 if ($this->validators
) {
43 return $this->validators
;
46 $validators = array();
47 $validators[] = new NumberValidator(array(
48 'locale' => 'en_US', // HTML5 uses "100.01" format
52 if (!empty($this->attributes
['inclusive'])) {
53 $inclusive = $this->attributes
['inclusive'];
56 if (isset($this->attributes
['min'])) {
57 $validators[] = new GreaterThanValidator(array(
58 'min' => $this->attributes
['min'],
59 'inclusive' => $inclusive
62 if (isset($this->attributes
['max'])) {
63 $validators[] = new LessThanValidator(array(
64 'max' => $this->attributes
['max'],
65 'inclusive' => $inclusive
69 if (!isset($this->attributes
['step'])
70 ||
'any' !== $this->attributes
['step']
72 $validators[] = new StepValidator(array(
73 'baseValue' => (isset($this->attributes
['min'])) ?
$this->attributes
['min'] : 0,
74 'step' => (isset($this->attributes
['step'])) ?
$this->attributes
['step'] : 1,
78 $this->validators
= $validators;
79 return $this->validators
;
83 * Provide default input rules for this element
85 * Attaches a number validator, as well as a greater than and less than validators
89 public function getInputSpecification()
92 'name' => $this->getName(),
95 array('name' => 'Zend\Filter\StringTrim')
97 'validators' => $this->getValidators(),