'FlatPickr: DateTime – Increase second datetime minDate (or minTime) by hours or minutes rather than full days
With great shame, I've now spent several hours across multiple days only to continue failing to figure this one out:
How can I create a flatpickr onChange event where the minDate (or minTime?) of the second datetime input is +x hours or minutes relative to the first datetime input selection? I can't figure out how to set a relative increase less than one full day.
These config options are successfully forcing the second input's minDate to be that of the first input's datetime output down to the minute, but will accept the very same time:
// Start Date and Time: input_144_5
const startDate = $('#input_144_5').flatpickr({
enableTime: true,
dateFormat: "Y-m-d H:i",
altInput: true,
altFormat: "D, F j \\a\\t h:i K",
defaultDate: new Date(),
onChange: function(selectedDates, dateStr, instance) {
endDate.set('minDate', new Date(dateStr))
}
});
// End Date and Time: input_144_6
const endDate = $('#input_144_6').flatpickr({
enableTime: true,
dateFormat: "Y-m-d H:i",
altInput: true,
altFormat: "D, F j \\a\\t h:i K",
});
While this one is successfully setting the second input's minimum to +1 full day:
// Start Date and Time: input_144_5
var startDate = $('#input_144_5').flatpickr({
enableTime: true,
dateFormat: "Y-m-d H:i",
altInput: true,
altFormat: "D, F j \\a\\t h:i K",
defaultDate: new Date(),
onChange: function(selectedDates, dateStr, instance) {
endDate.set('minDate', new Date(dateStr).fp_incr(1))
}
});
// End Date and Time: input_144_6
var endDate = $('#input_144_6').flatpickr({
enableTime: true,
dateFormat: "Y-m-d H:i",
altInput: true,
altFormat: "D, F j \\a\\t h:i K",
});
Is there any way to set—or restrict—fp_incr() in a way that only increases the minute value by +1, or maybe targets the minutes portion of the dateStr exclusively?
FlatPickr documentation here if helpful.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|