showing results for - "datepicker prevent choose day"
Lya
28 Oct 2019
1//MUST ADD:
2<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" defer />
3
4  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"
5integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30="
6crossorigin="anonymous"></script>
7
8// php (cakephp)
9
10<div class="col-sm-4 col-xs-12">
11  <?php echo $this->Form->input('delivery_date', array(
12    'class' => 'form-control', 'label' => false, 'placeholder' => __d('frontend', 'select_delivery_date'), 'required')); ?>    </div>
13</div>
14
15// java script
16
17function addDays(date, days) {
18  var result = new Date(date);
19  result.setDate(date.getDate() + days);
20  return result;
21}
22
23
24$('#InoviceDeliveryDate').datepicker({
25		orientation: 'bottom',
26		format: 'yyyy-mm-dd',
27		todayBtn: "linked",
28		autoclose: true,
29		todayHighlight: true,
30		maxViewMode: 0,
31		beforeShowDay: function(date) {
32
33			startDate = new Date(); 
34			endDate = addDays(startDate, 30); // extent 30 days more
35
36			start 		= startDate.getTime();
37			end 		= endDate.getTime();
38			current 	= date.getTime();
39
40            // prevent choose this date on calendar; 2021/02/12, 2021/02/13, 2021/02/14
41			special_dates = [];
42			special_dates.push(new Date('2021/02/12').getTime());
43			special_dates.push(new Date('2021/02/13').getTime());
44			special_dates.push(new Date('2021/02/14').getTime());
45
46			if (start <= current && current <= end) {
47				for (var i = 0; i < special_dates.length; i++) {
48
49					console.log(special_dates[i] + " " + current);
50					if (current === special_dates[i]) {
51						return [ false, "", "unAvailable" ];
52
53					}
54				}
55				return [ true, "", "Available" ];
56
57			} else {
58				return [ false, "", "unAvailable" ];
59			}
60
61		},
62		//language: 'custom',
63	}).on('changeDate', function(e) {
64		// `e` here contains the extra attributes
65		$('#InoviceDeliveryDate').datepicker('hide');
66	});