Date Validation
Enforcing validation is essential to a great UX. First make sure to have the min & max values right and then work your way through disabled values.
Depending on your situation, you have two options:
- Set invalid - set the invalids through the
invalidoption. - Set valid - set the valids through the
validoption.
Both the invalid and valid options support the following:
- Exact dates - Passing exact values like:
'2020-05-20'will disable/enable the specific day - Date ranges - Passing
startandendvalue pairs will disable/enable specific days that fall into that range - Recurring dates - Passing recurrence rules as objects or in RRULE string format will be parsed. For more information on recurrence check out the rule generator
Exact dates and the start/end pairs can be passed as JS date objects, ISO date strings or Moment.js objects. Having invalids set up correctly not just enhances the UX, but improves performance.
The passed date-times can also contain timezone data which requires a timezonePlugin to be interpreted correctly.
Demo
(useful for accommodation booking)
jsmobiscroll.datepicker('#datepicker', {
controls: ['calendar '],
select: 'range',
inRangeInvalid: true ,
rangeEndInvalid: false ,
invalid: []
valid: []
}); mobiscroll.setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
});
mobiscroll.datepicker('#demo', {
controls: ['calendar'],
select: 'range',
display: 'inline',
invalid: [
'2020-02-12',
'2020-05-20',
{
recurring: {
repeat: 'weekly',
weekDays: 'SA,SU',
},
},
{
recurring: {
repeat: 'yearly',
day: 24,
month: 12,
},
},
{
recurring: {
repeat: 'yearly',
day: 31,
month: 12,
},
},
{
recurring: {
repeat: 'monthly',
day: 1,
},
},
{
recurring: {
repeat: 'monthly',
day: -1,
},
},
{
start: '2020-03-15',
end: '2020-03-30',
},
{
start: '2020-07-05',
end: '2020-08-20',
},
],
});
<div id="demo"></div>