问题
I have two calendars (startDate and endDate) I have a function to disable all days excepts mondays or enable the next working day to the holiday monday in the startDate calendar. And I have a function to disable all days excepts fridays or enable the previous working day to the holiday friday in the endDate calendar. When I select a date in the startDate calendar it selects automatically some enabled date in the endDate calendar and vice versa. When the user changes the month or the year in any calendar, the calendar is closed and I need that they remain opened. And I also need that when I select a date in the startDate calendar it calls the function that disables the dates in the another calendar. It seems that the function runs but it don't disable the days of the another calendar
javascript functions:
<h:panelGroup id="scriptPG">
<script>
//<![CDATA[
function disableStartDateDays(date) {
var daysToDisable = #{bean.disableStartDates};
var month = date.getMonth(), day = date.getDate(), year = date.getFullYear();
for (i = 0; i < daysToDisable.length; i++) {
if ($.inArray((month + 1) + '-' + day + '-' + year, daysToDisable) != -1) {
return [ false ];
}
}
return [ true ];
}
function disableEndDateDays(date) {
var daysToDisable = #{bean.disableEndDates};
var month = date.getMonth(), day = date.getDate(), year = date.getFullYear();
for (i = 0; i < daysToDisable.length; i++) {
if ($.inArray((month + 1) + '-' + day + '-' + year, daysToDisable) != -1) {
return [ false ];
}
}
return [ true ];
}
//]]>
</script>
</h:panelGroup>
Calendars:
<p:calendar id="startDate" widgetVar="startDateWV" ... >
<p:ajax event="dateSelect"
listener="#{bean.selectEndDate}"
oncomplete="disableEndDateDays(PF('startDateWV').getDate());"
process="@this"
update="endDateCAL @this" />
<p:ajax event="viewChange"
listener="#{bean.findDaysToDisableStartDate}"
process="@this endDateCAL"
update="@this scriptPG" />
</p:calendar>
<p:calendar id="endDate" widgetVar="endDateWV" ... >
<p:ajax event="dateSelect"
listener="#{bean.selectStartDate}"
oncomplete="disableStartDateDays(PF('endDateWV').getDate());"
process="@this"
update="startDateCAL @this" />
<p:ajax event="viewChange"
listener="#{bean.findDaysToDisableEndDate}"
process="@this startDateCAL"
update="@this scriptPG" />
</p:calendar>
startDate calendar:
endDate calendar:
来源:https://stackoverflow.com/questions/31998536/disable-days-in-the-other-calendar-when-a-month-or-a-year-is-changed