Skip to content

Commit

Permalink
Include max date in error msg for date.between
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle committed Nov 4, 2023
1 parent 977cd5e commit 07cd602
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/fields/date.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
'key' => 'validation.date.between',
'data' => [
'min' => $min->format($format),
'max' => $min->format($format)
'max' => $max->format($format)
]
]);
} elseif ($min && $value->isMin($min) === false) {
Expand Down
28 changes: 26 additions & 2 deletions tests/Form/Fields/DateFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ public function testMinMax()
$field->validate();
$this->assertFalse($field->isValid());
$this->assertTrue($field->isInvalid());
$this->assertSame([
'minMax' => 'Please enter a date between 01.10.2020 and 02.10.2020',
], $field->errors());

// min & max failed (with time)
$field = $this->field('date', [
'time' => true,
'min' => '2020-10-01 10:04',
'max' => '2020-10-02 08:15',
'value' => '2020-10-03 12:34'
]);

$field->validate();
$this->assertFalse($field->isValid());
$this->assertTrue($field->isInvalid());
$this->assertSame([
'minMax' => 'Please enter a date between 01.10.2020 10:04 and 02.10.2020 08:15',
], $field->errors());

// min failed
$field = $this->field('date', [
Expand All @@ -90,16 +108,22 @@ public function testMinMax()
$field->validate();
$this->assertFalse($field->isValid());
$this->assertTrue($field->isInvalid());
$this->assertSame([
'minMax' => 'Please enter a date after 01.10.2020',
], $field->errors());

// max failed
$field = $this->field('date', [
'value' => '2020-11-10',
'max' => '2020-10-31'
'max' => '2020-10-31',
'value' => '2020-11-10'
]);

$field->validate();
$this->assertFalse($field->isValid());
$this->assertTrue($field->isInvalid());
$this->assertSame([
'minMax' => 'Please enter a date before 31.10.2020',
], $field->errors());
}

public function valueProvider()
Expand Down

0 comments on commit 07cd602

Please sign in to comment.