0

I got such kind of problem - I need to check in my JSF/PrimeFaces page if p:calendar value (entered by user with keyboard) is empty and if it so to clear error message

this is my JSF Calendar snippet

 <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>

this is my JS snippet

function hideCustomerCalendarErrMsg(variable) {
    var inputField, msg;
    inputField = PF('dateBirthVar').getDate();
    msg = document.getElementById("createEditCustomerForm:accordion:m_" +variable);
    if (inputField.value === null) {
        msg.innerHTML = "";
    }
}

so, please help me - it doesnt work. And I need to clear validator err message on the fly if user clear the field of calendar

1 Answer 1

2

Instead of calling getDate(), try to check the input itself for empty value.

function hideCustomerCalendarErrMsg(variable) {
   var inputField, msg;
   inputField = PF('dateBirthVar').input;
   msg = document.getElementById("createEditCustomerForm:accordion:m_" + variable);
   if (inputField.val() === "") {
       msg.innerHTML = "";
    }
}

Or you can still have your code as it is, but instead of

if (inputField.value === null)

Go for

if (inputField === null)
5
  • I did it( but it is also dont work - function hideCustomerCalendarErrMsg(variable) { var inputField, msg; inputField = PF('dateBirthVar').input; msg = document.getElementById("createEditCustomerForm:accordion:m_dateBirth"); if (inputField.value === null) { msg.innerHTML = "";}} Commented Jun 30, 2017 at 13:21
  • yes because you still have if (inputField.value === null) replace it with if (inputField.val() === "") @DmitriyLaletin Commented Jun 30, 2017 at 13:22
  • I do as you said - function hideCustomerCalendarErrMsg(variable) { var inputField, msg; inputField = PF('dateBirthVar').input; msg = document.getElementById("createEditCustomerForm:accordion:m_dateBirth"); if (inputField.val === "") { msg.innerHTML = "";}} Commented Jun 30, 2017 at 13:36
  • but it is still dont works( I spend the whole night on this bug(( can I ask you for a favor - is it possible to show you my code and result by skype - dima.laletin I will be very gratefull if you will find few minutes Commented Jun 30, 2017 at 13:37
  • btw have a look at this article, can help you a lot in dealing with widgetVar blog.hatemalimam.com/intro-to-primefaces-widgetvar Commented Jun 30, 2017 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.