I’m trying to work out how to dynamically enable and disable dates using MultiDatesPicker for jQuery UI. http://luca.lauretta.info/Multiple-Dates-Picker-for-jQuery-UI/
I can use addDisabledDates and pass an array of dates to the picker, these dates will then show as disabled. That works, but how do I enable them again ?
I’ve tried amending the array of dates, and recalling the date picker, but that doesn’t seem to load the new dates.. the old dates are still showing as disabled.
This is a sample of what I’m doing:
$(document).ready(function() {
addeddates = ['1 January 1970', '5 November 2024', '6 November 2024']
datepicker()
function datepicker() {
$('.cals').multiDatesPicker({
dateFormat: "d MM yy",
minDate: 0, // today
maxDate: 365, // +30 days from today
multidate: true,
defaultDate:"0d",
addDisabledDates: addeddates,
beforeShow: function(d) {
addeddates = ['1 January 1970']
datepicker()
}
})
}
})
When the date picker is called 5th and 6th November are disabled. I was hoping updating the addeddates
array to be only one day and then recalling the function would allow them to be usable.
Is there anyway to dynamically enable / disable the dates ?
I’m open to using another date picker if it supports multiple dates and can be using on multiple input fields on the same page.
Thanks
2
Answers
I've got this working using multiDatesPicker and created a fiddle here showing it working. https://jsfiddle.net/hb709gkx/
This allows you to select dates in any of the date fields, they are then not available in the other date fields. When you go into a field its dates can be deselected. Seems to work OK.
Looks like you have to rebuild them each time.
https://jsfiddle.net/Twisty/om7hu4ga/60/
JavaScript
I disabled the secondary ones until the first had a value. Not doing this might throw errors about them not being initialized as MultiDatePckers or DatePicker.