From 215c61c3959b642e3dae1825f6b45af80d03598a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 29 Mar 2017 16:57:15 +0200 Subject: [PATCH] Validators: fixed compatibility with latest nette/utils Range can contain empty strings when reference to another form field is used: addRule($form::RANGE, NULL, [$form['min'], $form['max']) --- src/Forms/Validator.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Forms/Validator.php b/src/Forms/Validator.php index 5a311e1a3..5537c3fa0 100644 --- a/src/Forms/Validator.php +++ b/src/Forms/Validator.php @@ -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); } @@ -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]); } @@ -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]); }