Numeric input: validate inclusive ranges

This commit is contained in:
Alexander A. Klimov 2018-04-12 14:25:10 +02:00
parent a187966277
commit 5cf51a70c8
1 changed files with 7 additions and 6 deletions

View File

@ -46,11 +46,12 @@ class Number extends FormElement
*/ */
public function init() public function init()
{ {
if ($this->min !== null) { if ($this->min !== null || $this->max !== null) {
$this->addValidator('GreaterThan', true, array('min' => $this->min)); $this->addValidator('Between', true, array(
} 'min' => $this->min === null ? -INF : $this->min,
if ($this->max !== null) { 'max' => $this->max === null ? INF : $this->max,
$this->addValidator('LessThan', true, array('max' => $this->max)); 'inclusive' => true
));
} }
} }
@ -86,7 +87,7 @@ class Number extends FormElement
*/ */
public function setMax($max) public function setMax($max)
{ {
$this->max = (int) $max; $this->max = (float) $max;
return $this; return $this;
} }