Skip to content

Commit f6b129b

Browse files
committed
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'])
1 parent 4674420 commit f6b129b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Forms/Validator.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ public static function validateValid(Controls\BaseControl $control): bool
152152
*/
153153
public static function validateRange(IControl $control, array $range): bool
154154
{
155+
$range = array_map(function ($v) {
156+
return $v === '' ? NULL : $v;
157+
}, $range);
155158
return Validators::isInRange($control->getValue(), $range);
156159
}
157160

@@ -161,7 +164,7 @@ public static function validateRange(IControl $control, array $range): bool
161164
*/
162165
public static function validateMin(IControl $control, $minimum): bool
163166
{
164-
return Validators::isInRange($control->getValue(), [$minimum, NULL]);
167+
return Validators::isInRange($control->getValue(), [$minimum === '' ? NULL : $minimum, NULL]);
165168
}
166169

167170

@@ -170,7 +173,7 @@ public static function validateMin(IControl $control, $minimum): bool
170173
*/
171174
public static function validateMax(IControl $control, $maximum): bool
172175
{
173-
return Validators::isInRange($control->getValue(), [NULL, $maximum]);
176+
return Validators::isInRange($control->getValue(), [NULL, $maximum === '' ? NULL : $maximum]);
174177
}
175178

176179

0 commit comments

Comments
 (0)