Skip to content

Commit

Permalink
Merge pull request #5 from DestinationCore/bug/no-start-validation
Browse files Browse the repository at this point in the history
Add validation for if the end date is set but start date isn't
  • Loading branch information
TraffordFewster authored Jun 21, 2022
2 parents 630e29b + 24a873c commit 970cedd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## 1.4.2 - 21-06-22
### Added:
- Validation for if the end date is set but start date isn't.

### Changed:
- Validation messages to be more user friendly.

## 1.4.1 - 23-05-22
### Fixed
- `endRepeatDate` `DateTime` object time manually set to end of day (23:59:59).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "unionco/calendarize",
"description": "A calendar field type providing functionality for recurrence.",
"version": "1.4.1",
"version": "1.4.2",
"type": "craft-plugin",
"keywords": [
"craft",
Expand Down
19 changes: 15 additions & 4 deletions src/fields/CalendarizeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace unionco\calendarize\fields;

use yii\validators\Validator;
use Craft;

class CalendarizeValidator extends Validator {

Expand All @@ -20,9 +21,19 @@ protected function validateValue($value)
{
if ($value->startDate && !$value->endDate) {
return [
\Craft::t(
Craft::t(
'calendarize',
'End Date must be set if start date is not null'
'End Date must be set if the start date is set.'
),
[]
];
}

if (!$value->startDate && $value->endDate) {
return [
Craft::t(
'calendarize',
'Start Date must be set if the end date is set.'
),
[]
];
Expand All @@ -31,7 +42,7 @@ protected function validateValue($value)
if ($value->startDate && $value->endDate) {
if ($value->endDate < $value->startDate) {
return [
\Craft::t(
Craft::t(
'calendarize',
'End Date must be greater than or equal to your Start Date'
),
Expand All @@ -42,7 +53,7 @@ protected function validateValue($value)

if (isset($value->endRepeat) && $value->endRepeat === 'date' && !$value->endRepeatDate) {
return [
\Craft::t(
Craft::t(
'calendarize',
'End Repeat Date is required if repeating ends on date'
),
Expand Down

0 comments on commit 970cedd

Please sign in to comment.