簡體   English   中英

在JQuery中獲取richfaces日歷的選定日期

[英]get selected date of richfaces calendar in JQuery

我有兩個相同形式的rich:calendar ,都是rich:calendar 一個是開始日期 (或激活日期),另一個是結束日期 (或停用日期)。

我想要實現的是在結束日期日歷中標記選定的開始日期

例如:

在此輸入圖像描述

7月14日(紅色)是開始日期 ,7月16日是當前選定的結束日期

我的問題似乎是,我無法通過JQuery獲得開始日期的值。 我試圖在頁面的某處“隱藏”這個值,所以我可以用$('#myForm\\\\:hiddenActivationDate').val();來訪問它$('#myForm\\\\:hiddenActivationDate').val(); 它幾乎起作用..但是其他一切都停止了工作。

這些是我寫的腳本函數:

var currentDate = new Date();
function activationDateDisablementFunction(day) {
    return currentDate.getDate() <= day.date.getDate();
}
function activationDateClassProv(day) {
    if (currentDate.getDate() > day.date.getDate()) {
        return "disabledDay";
    }
}
function deactivationDateDisablementFunction(day) {
    var hiddenActivationDate = $('#myForm\\:hiddenActivationDate').val();
    var activationDate = new Date(Date.parse(hiddenActivationDate));
    return day.date.getDate() >= activationDate.getDate(); // true = enabled, false =disabled
}
function deactivationDateClassProv(day) {
    var hiddenActivationDate = $('#myForm\\:hiddenActivationDate').val();
    var activationDate = new Date(Date.parse(hiddenActivationDate));
    if (day.date.getDate() < activationDate.getDate()) {
        return "disabledDay";
    }
    if (day.date.getDate() === activationDate.getDate()) {
        return "activatedDay";
    }
}

這里有兩個日歷:

<!-- start date -->
<a4j:outputPanel id="activationDateCalendar" layout="block" >
    <rich:calendar value="#{myBean.activationDate}"
                   popup="true"     
                   datePattern="#{myBean.dateFormat}"     
                   boundaryDatesMode="scroll"    
                   jointPoint="bottomAuto"
                   showWeeksBar="false"
                   showApplyButton="false" 
                   dayClassFunction="activationDateClassProv" 
                   dayDisableFunction="activationDateDisablementFunction"
                   style="width:320px">
        <a4j:ajax render="@this, hiddenActivationDate, deactivationDateCalendar,  activationDatePreview, deactivationDatePreview, durationPreview" />
    </rich:calendar>
</a4j:outputPanel>

<!-- my hidden date -->
<h:inputHidden id="hiddenActivationDate" value="#{myBean.activationDate}" />

<!-- end date -->
<a4j:outputPanel id="deactivationDateCalendar" layout="block" >
    <rich:calendar value="#{myBean.deactivationDate}"
                   popup="true"     
                   datePattern="#{myBean.dateFormat}"     
                   boundaryDatesMode="scroll"    
                   jointPoint="bottomAuto"
                   showWeeksBar="false"
                   showApplyButton="false"
                   dayClassFunction="activationDateClassProv" 
                   dayDisableFunction="activationDateDisablementFunction"
                   style="width:320px">
        <a4j:ajax render="@this, activationDatePreview, deactivationDatePreview, durationPreview" />                           
    </rich:calendar>
</a4j:outputPanel>

簡而言之
我想要做的是直接從JQuery函數deactivationDateClassProv訪問開始日期值,而不從隱藏字段獲取它。

這可能嗎? 還是有“Richfaces方式”?

RichFaces組件有一個JS API,閱讀文檔

在您的情況下,您只需訪問日期:

function deactivationDateClassProv(day) {
    var hiddenActivationDate = #{rich:component('firstCalendarId')}.getValue();
    …
}

請注意,該函數僅在需要時調用,如果您只是關閉並打開日歷,則不會再次調用它(除非您切換月份或將isRendered設置為false)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM