timepicker-ui
4.7.0GitHub
timepicker-ui
Features / Disabled Time

Disabled Time

Restrict specific hours, minutes, or time ranges

Disabled Hours

#

Disable specific hours from selection:

const picker = new TimepickerUI(input, {
clock: {
disabledTime: {
hours: [1, 3, 5, 8, 10, 12]
}
}
});
picker.create();

Disabled Minutes

#

Disable specific minutes from selection:

const picker = new TimepickerUI(input, {
clock: {
disabledTime: {
minutes: [15, 30, 45]
}
}
});
picker.create();

Time Range

#

Disable a time range with disabledTime.ranges (the hours, minutes and seconds lists are ignored when ranges is set):

const picker = new TimepickerUI(input, {
clock: {
type: '12h',
disabledTime: {
ranges: '10:00 AM - 2:00 PM'
}
}
});
picker.create();

Multiple Time Ranges

#

Disable multiple time ranges:

const picker = new TimepickerUI(input, {
clock: {
type: '12h',
disabledTime: {
ranges: [
'9:00 AM - 11:00 AM',
'1:00 PM - 3:00 PM',
'5:00 PM - 7:00 PM'
]
}
}
});
picker.create();

24h Format with Range

#

Disable time range in 24h format:

const picker = new TimepickerUI(input, {
clock: {
type: '24h',
disabledTime: {
ranges: '00:00 - 08:00'
}
}
});
picker.create();

Dynamic DisabledTime Update

#

Update disabled times at runtime with the setOptions() method:

const picker = new TimepickerUI(input, {
clock: {
type: '24h',
disabledTime: { hours: [9, 10, 11, 12] }
}
});
picker.create();
// Later, update disabled times
picker.setOptions({
clock: {
disabledTime: { hours: [0, 1, 2, 3, 4, 5, 6, 7, 8] }
}
});

Dynamic Range Update

#

Update disabled ranges at runtime for shift scheduling or business rules:

const picker = new TimepickerUI(input, {
clock: {
type: '24h',
disabledTime: { ranges: '09:00 - 12:00' }
}
});
picker.create();
// Update to a different range
picker.setOptions({
clock: {
disabledTime: { ranges: '14:00 - 18:00' }
}
});
// Update to multiple ranges
picker.setOptions({
clock: {
disabledTime: {
ranges: ['00:00 - 08:00', '12:00 - 13:00', '18:00 - 23:59']
}
}
});
// Switch from ranges to hours
picker.setOptions({
clock: {
disabledTime: { hours: [20, 21, 22, 23] }
}
});

Disable with a Function

#

clock.isTimeDisabled decides per time. This one allows 09:00 to 16:59 only. The button adds a lunch break at 12:00 and calls refreshDisabledTime(), so the picker re-reads the function without a re-render.

Lunch break: off
let lunchBreak = false;
const picker = new TimepickerUI(input, {
clock: {
type: '24h',
isTimeDisabled: ({ hour }) => {
if (hour < 9 || hour >= 17) return true;
return lunchBreak && hour === 12;
}
},
ui: { inline: { enabled: true, container: '#picker', autoUpdate: true } }
});
picker.create();
toggleButton.addEventListener('click', () => {
lunchBreak = !lunchBreak;
picker.refreshDisabledTime();
});
Esc