From 815b4f64b8353bd7542abe5f834de4863a896316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Mon, 10 Jul 2023 11:20:03 +0100 Subject: [PATCH] fix: form number input validation --- .../Requests/Front/FormSubmissionRequest.php | 4 ++-- tests/Feature/FormTest.php | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/Http/Requests/Front/FormSubmissionRequest.php b/app/Http/Requests/Front/FormSubmissionRequest.php index 07f1b967..65b78966 100644 --- a/app/Http/Requests/Front/FormSubmissionRequest.php +++ b/app/Http/Requests/Front/FormSubmissionRequest.php @@ -121,8 +121,8 @@ private function rulesFile(Block $field, array $rules): array private function rulesNumber(Block $field, array $rules): array { - $min_value = $field->input('min_value'); - $max_value = $field->input('max_value'); + $min_value = $field->input('min_value') ?: null; + $max_value = $field->input('max_value') ?: null; $rules[] = 'integer'; diff --git a/tests/Feature/FormTest.php b/tests/Feature/FormTest.php index f9af741b..e6dce4a7 100644 --- a/tests/Feature/FormTest.php +++ b/tests/Feature/FormTest.php @@ -288,6 +288,30 @@ public static function fields(): array 'invalid' => 25, ], ], + 'number-min-0' => [ + [ + 'type' => 'number', + 'required' => false, + 'min_value' => 0, + 'max_value' => 1, + ], + [ + 'valid' => 1, + 'invalid' => 5, + ], + ], + 'number-max-0' => [ + [ + 'type' => 'number', + 'required' => false, + 'min_value' => 5, + 'max_value' => 0, + ], + [ + 'valid' => \PHP_INT_MAX, + 'invalid' => 3, + ], + ], // Date 'date-required' => [