Skip to content

Commit

Permalink
fix: form number input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Jul 10, 2023
1 parent 6d5da47 commit 815b4f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/Http/Requests/Front/FormSubmissionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
24 changes: 24 additions & 0 deletions tests/Feature/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down

0 comments on commit 815b4f6

Please sign in to comment.