Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery UI datepicker. Disable array of Dates

I have been trying to search for a solution to my Jquery ui datepicker problem and I'm having no luck. Here's what I'm trying to do...

I have an application where i'm doing some complex PHP to return a JSON array of dates that I want BLOCKED out of the Jquery UI Datepicker. I am returning this array:

["2013-03-14","2013-03-15","2013-03-16"] 

Is there not a simple way to simply say: block these dates from the datepicker?

I've read the UI documentation and I see nothing that helps me. Anyone have any ideas?

like image 441
Daniel White Avatar asked Mar 14 '13 03:03

Daniel White


People also ask

How to disable particular dates in datepicker?

Luckily bootstrap datepicker already provided an option called datesDisabled then we will just put the value of our dates for disabled as array variable as you can see below: var datesForDisable = ["08-5-2021", "08-10-2021", "08-15-2021", "08-20-2021"] $('. datepicker').

How do I enable only certain dates in datepicker?

Answers. To achieve this function, you can use beforeShowDay in the datepicker to do it.


1 Answers

You can use beforeShowDay to do this

The following example disables dates 14 March 2013 thru 16 March 2013

var array = ["2013-03-14","2013-03-15","2013-03-16"]  $('input').datepicker({     beforeShowDay: function(date){         var string = jQuery.datepicker.formatDate('yy-mm-dd', date);         return [ array.indexOf(string) == -1 ]     } }); 

Demo: Fiddle

like image 145
Arun P Johny Avatar answered Oct 13 '22 05:10

Arun P Johny