Skip to content

Commit

Permalink
Validators: fixed compatibility with latest nette/utils
Browse files Browse the repository at this point in the history
Range can contain empty strings when reference to another form field is used: addRule($form::RANGE, NULL, [$form['min'], $form['max'])
  • Loading branch information
dg committed Mar 29, 2017
1 parent 42bed3f commit 215c61c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Forms/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public static function validateValid(Controls\BaseControl $control)
*/
public static function validateRange(IControl $control, $range)
{
$range = array_map(function ($v) {
return $v === '' ? NULL : $v;
}, $range);
return Validators::isInRange($control->getValue(), $range);
}

Expand All @@ -171,7 +174,7 @@ public static function validateRange(IControl $control, $range)
*/
public static function validateMin(IControl $control, $minimum)
{
return Validators::isInRange($control->getValue(), [$minimum, NULL]);
return Validators::isInRange($control->getValue(), [$minimum === '' ? NULL : $minimum, NULL]);
}


Expand All @@ -183,7 +186,7 @@ public static function validateMin(IControl $control, $minimum)
*/
public static function validateMax(IControl $control, $maximum)
{
return Validators::isInRange($control->getValue(), [NULL, $maximum]);
return Validators::isInRange($control->getValue(), [NULL, $maximum === '' ? NULL : $maximum]);
}


Expand Down

0 comments on commit 215c61c

Please sign in to comment.