Reputation: 833
How to limit
I'm trying to limit the time a user can select from this plugin: https://github.com/Eonasdan/bootstrap-datetimepicker
I've searched around this site and google for similar questions, but users generally ask for the validation to work between one known period and another known period. e.g 9:00 - 21:00 2015/03/09 9:00 - 2015/03/10 21:00. If a user inputs 2015/03/09 23:00 the validation will pass this because the time is within those two min/max periods.
I need it to work as a booking system works, so that each day is limited between those times. e.g if a user selects 2015/03/09 23:00 or 2015/03/10 5:00 then the validation won't pass, it will only pass on any day between 9:00 & 21:00.
$('.datetimepicker').datetimepicker({
stepping: 30,
minDate: moment({hour: 9, minute: 30}),
format: 'YYYY-MM-DD HH:mm'
});
This starts the min date for today at 9:30am, but if I was to choose any day after today I would be able to select for example 4am - anything under 9:30am
Upvotes: 12
Views: 18325
Reputation: 141
Use the enabledHours property:
$('.datetimepicker').datetimepicker({
stepping: 30,
enabledHours: [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
format: 'YYYY-MM-DD HH:mm'
});
This way it should allow any hours between 9:00 and 20:30, but won't allow anything from 21:00 on. More at http://eonasdan.github.io/bootstrap-datetimepicker/Options/#endisabledhours.
Upvotes: 12