Disable days in the other calendar when a month or a year is changed

可紊 提交于 2020-01-06 20:37:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!