0
我得到了這樣那樣的問題 - 我需要在我的JSF/PrimeFaces頁,以檢查p:calendar
值(用鍵盤用戶輸入)是空的,如果這麼清楚的錯誤消息如何檢查JS如果p:日曆值爲空?
這是我的JSF日曆片段
<div class="item">
<p:outputLabel id="l_dateBirth" for="dateBirth" value="#{msgs['customerForm.dateBirth']}"/>
<p:calendar id="dateBirth" widgetVar="dateBirthVar" value="#{customerBean.customer.dateOfBirth}"
placeholder="MM/dd/yyyy"
showOn="button" navigator="true"
pattern="MM/dd/yyyy" yearRange="-120:+0"
mindate="#{dateBean.minDate}"
maxdate="#{dateBean.maxDateOfBirth}"
required="true"
requiredMessage="#{msgs['Error.dateBirth.mandatory']}"
disabled="#{customerBean.mode eq 'EDIT'}">
<f:ajax execute="@this" event="dateSelect" render="m_dateBirth" />
<p:ajax event="keyup" oncomplete="hideCustomerCalendarErrMsg('dateBirth')" />
<f:validator binding="#{dateOfBirthValidator}"/>
</p:calendar><p:message id="m_dateBirth" for="dateBirth" display="text"/>
</div>
這是我的JS代碼片段
function hideCustomerCalendarErrMsg(variable) {
var inputField, msg;
inputField = PF('dateBirthVar').getDate();
msg = document.getElementById("createEditCustomerForm:accordion:m_" +variable);
if (inputField.value === null) {
msg.innerHTML = "";
}
}
的話,請幫我 - 它不工作。如果用戶清除日曆字段,我需要清除驗證器錯誤消息
我做到了(但也不要工作 - 函數hideCustomerCalendarErrMsg(variable){var inputField,msg; inputField = PF('dateBirthVar').input; msg = document.getElementById(「createEditCustomerForm:accordion:m_dateBirth」); (inputField.value === null){if(inputField.value === null){ msg.innerHTML =「」;}} –
是的,因爲你仍然有'if(inputField.value === null)'用'if(inputField.val )===「」)'@DmitriyLaletin –
我照你所說的去做 - function hideCustomerCalendarErrMsg(variable){var inputField,msg; inputField = PF('dateBirthVar')。input; msg = document.getElementById(「createEditCustomerForm:accordion:m_dateBirth」);如果(inputField.val ===「」){ msg.innerHTML =「」;}} –