I use jQuery UI Datepicker and an extension for it https://habr.com/ru/en/post/303186/
At the moment I am using this code for the datepicker:
$(function() { var array = ["2016-11-20","2016-11-25","2016-12-03"] var string, day, month, year, cached = {}; $('#date_range').datepicker({ range: 'period', // режим - выбор периода numberOfMonths: 2, dateFormat: "dd.mm.yy", minDate: 0, maxDate: 14, onSelect: function(dateText, inst, extensionRange) { // extensionRange - объект расширения $('#date_range').val(extensionRange.startDateText + ' - ' + extensionRange.endDateText); }, beforeShowDay: function(date){ month = ('0' + (date.getMonth() + 1)).slice(-2); day = ('0' + (date.getDate())).slice(-2); year = date.getFullYear(); string = [year, month, day].join('-'); if(typeof cached[string] === 'undefined') { cached[string] = array.indexOf(string) === -1; } return [ cached[string], '', '' ] } }); // объект расширения (хранит состояние календаря) var extensionRange = $('#date_range').datepicker('widget').data('datepickerExtensionRange'); if(extensionRange.startDateText) $('[name=startDate]').val(extensionRange.startDateText); if(extensionRange.endDateText) $('[name=endDate]').val(extensionRange.endDateText); });
I need to make sure that when selecting the first date, there are 14 days that the user can choose, the rest of the dates become inactive.
For example, the user selects April 1 and shows that he can then choose only 15 days, until April 15. Or the user chooses April 15th and shows him that it is possible to choose dates up to April 30th, no more.
Tell me, how can this be done? Thank!