I need to enable only particular dates in a calendar, disabling all the other dates.
I tried with onCompleteTopics
and onBeforeShowDayTopics
using Struts2-jQuery DatePicker without success.
With raw jQuery I am able to do it as shown in this Fiddle
I need the same functionality using Struts2-jQuery DatePicker.
To enable only a particular set of dates (Close Event in the showcase) in Struts2-jQuery DatePicker, you need to use the onBeforeShowDayTopics
:
<script>
var availableDates = ["8-12-2014","25-12-2014","26-12-2014"];
$(function(){
$.subscribe('beforeDatepickerShow', function(event, data) {
var date = event.originalEvent.date;
var dmy = date.getDate() + "-"
+ (date.getMonth()+1) + "-"
+ date.getFullYear();
if ($.inArray(dmy, availableDates) != -1) {
event.originalEvent.returnValue = [true, "","Available"];
} else{
event.originalEvent.returnValue = [false,"","unAvailable"];
}
});
<script>
<sj:datepicker onBeforeShowDayTopics = "beforeDatepickerShow"
name = "myDate"
label = "With Close Event" />
Note: this feature was buggy in the past, so be sure you are not using an old version of the plugin.
Since 3.3.0 it is fixed and it works fine.