Restrictions Options
Restrictions allow you to prevent users from selected dates or times based on a set of rules.
new tempusDominus.TempusDominus(document.getElementById('datetimepicker1'),
{
restrictions: {
minDate: undefined,
maxDate: undefined,
disabledDates: [],
enabledDates: [],
daysOfWeekDisabled: [],
disabledTimeIntervals: [],
disabledHours: [],
enabledHours: []
}
}
)
minDate
Accepts: string | Date | DateTime Defaults: undefined
Prevents the user from selecting a date/time before this value. Set to
undefined
to remove
the
restriction.
Throws conflictingConfiguration if value is after maxDate.
maxDate
Accepts: string | Date | DateTime Defaults: undefined
Prevents the user from selecting a date/time after this value. Set to undefined
to remove the
restriction.
Throws conflictingConfiguration if value is after maxDate.
enabledDates/disabledDates
enabledDates
Allows the user to select only from the provided days. Setting this takes precedence over options.minDate, options.maxDate configuration.
disabledDates
Disallows the user to select any of the provided days. Setting this takes precedence over options.minDate, options.maxDate configuration.
enabledHours/disabledHours
Throws numbersOutOfRage any value is not between 0-23
enabledHours
Allows the user to select only from the provided hours.
disabledHours
Disallows the user to select any of the provided hours.
disabledTimeIntervals
Accepts: array of an object with from: DateTime, to: DateTime
Defaults:
undefined
Disables time selection between the given DateTimes.
const later = new tempusDominus.DateTime();
later.hours = 8;
new tempusDominus.TempusDominus(..., {
restrictions: {
disabledTimeIntervals: [
{ from: new tempusDominus.DateTime().startOf('date'), to: later }
]
}
});
daysOfWeekDisabled
Accepts: array of numbers from 0-6
Disallow the user to select weekdays that exist in this array. This has lower priority over the
options.minDate, options.maxDate, options.disabledDates and options.enabledDates configuration
settings.
Throws numbersOutOfRage any value is not between 0-6.