I would like to disable certain days in a jQuery UI datepicker based on the days entered in one of the input boxes by the user.
If i enter MWF it should only allow me to only select the dates which falls on either "M"onday , "W"ednesday ot "F"riday
I am able to dynamically construct the return value sting which needs to be set in the return statement.
for (var j=0; j < arr.length; j++)
mystr = mystr + "day != " + arr[j] + " && ";
mystr = mystr.substring(0, mystr.length - 3);
This gives me the following text in mystr variable:
day != 3 && day != 4 && day != 6
which needs to passed on to the return statement like :
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [(mystr)];
}
});
This is not working....
I am able to disable the days i want if i explicitly set it in return statement. But i need to dynamically restrict days selection in the datepicker based on days entered in the text box. I can get the days dynamically and also have the dynamic return statement ready. Its not working.
FULL CODE :
var batchdays = ['M', 'T', 'W', 'H', 'F', 'S'];
var batchcode= "MWF";
var batchdaysarray = batchcode.replace(/\d+/g, '').split('');
var arr = [];
var arrayLength = batchdaysarray.length;
for (var i = 0; i < arrayLength; i++) {
if ($.inArray(batchdaysarray[i], batchdays) != -1) {
arr.push($.inArray(batchdaysarray[i], batchdays)+1);
}
}
var mystr = '';
for (var j=0; j < arr.length; j++)
mystr = mystr + "day != " + arr[j] + " && ";
mystr = mystr.substring(0, mystr.length - 3);
alert(mystr);
console.log(mystr);
$('#actual_start_dt').datepicker({
dateFormat: 'dd-mm-yy',
prevText: '<i class="fa fa-chevron-left"></i>',
nextText: '<i class="fa fa-chevron-right"></i>',
beforeShowDay: function(date) {
var day = date.getDay();
return [(mystr)];
}
});
Please help