mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-26 00:23:33 +03:00
Add date validation to blocked periods (#432)
This commit is contained in:
parent
f3d7b78b15
commit
64ce83922d
2 changed files with 20 additions and 0 deletions
|
@ -83,10 +83,21 @@ class Blocked_periods_model extends EA_Model {
|
|||
// Make sure all required fields are provided.
|
||||
if (
|
||||
empty($blocked_period['name'])
|
||||
|| empty($blocked_period['start_datetime'])
|
||||
|| empty($blocked_period['end_datetime'])
|
||||
)
|
||||
{
|
||||
throw new InvalidArgumentException('Not all required fields are provided: ' . print_r($blocked_period, TRUE));
|
||||
}
|
||||
|
||||
// Make sure that the start date time is before the end.
|
||||
$start_date_time_object = new DateTime($blocked_period['start_datetime']);
|
||||
$end_date_time_object = new DateTime($blocked_period['end_datetime']);
|
||||
|
||||
if ($start_date_time_object >= $end_date_time_object)
|
||||
{
|
||||
throw new InvalidArgumentException('The start must be before the end date time value.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -261,6 +261,15 @@ App.Pages.BlockedPeriods = (function () {
|
|||
throw new Error(lang('fields_are_required'));
|
||||
}
|
||||
|
||||
const startDateTimeObject = App.Utils.UI.getDatetimepickerValue($startDateTime);
|
||||
const endDateTimeObject = App.Utils.UI.getDatetimepickerValue($endDateTime);
|
||||
|
||||
if (startDateTimeObject >= endDateTimeObject) {
|
||||
$startDateTime.addClass('is-invalid');
|
||||
$endDateTime.addClass('is-invalid');
|
||||
throw new Error(lang('start_date_before_end_error'));
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
$blockedPeriods.find('.form-message').addClass('alert-danger').text(error.message).show();
|
||||
|
|
Loading…
Reference in a new issue