I want to enable particular dates and disable it after completing task.I dont know how to start and what to do first.Please suggest me.
"02-03-2016","19-03-2016","23-03-2016",
I want to enable particular dates and disable it after completing task.I dont know how to start and what to do first.Please suggest me.
"02-03-2016","19-03-2016","23-03-2016",
It was a bit hard to understand your needs but I guess that you are using datepicker and you want to disable and renable some particular dates.
You do it by using beforeShowDay
while you instantiate your datepicker. Before to respond your question, let's start by reminding what the beforeShowDate does:
A function that takes a date as a parameter and must return an array with:
[0]: true/false indicating whether or not this date is selectable [1]: a CSS class name to add to the date's cell or "" for the default presentation [2]: an optional popup tooltip for this date
The function is called for each day in the datepicker before it is displayed.
So to disable a specific date you need to return [false]
in the function beforeShowDate
when you have in parameteter the date you want to disable and [true]
if not. So I urge you to use a global variable dateDisabledArray
where you put all the date you want to disable. So here's a small code where I disable these dates : "2016-03-11","2016-03-02" and "2016-03-24":
var dateDisabledArray = ["2016-03-11","2016-03-02","2016-03-24"];
$('input').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ dateDisabledArray.indexOf(string) == -1 ]
}
});
Now if you want to renable the previous dates, you only have to do :
dateDisabledArray = [];
Here's a jsfiddle where I disable these dates on a click and renable them in the folowing click.