0

I have a field which is required and for which want to do a validation of the field value when the onblur event occurs. The problem is that when I add the ajax onblur event that validates the format of the data, if I put the focus on the field and pass to the next field without entering data, the required validation appears, and I don't want validate this until the submit event. How I can avoid this? My code is as follows:

<p:outputLabel value="#{i18n['identifier']}" for="nif" styleClass="ep-data-edit-field"/>
<p:inputText id="nif" value="#{personModelBean.tgssPerson.identifier}"
             required="#{personSimpleModelBean.fieldValidationError == null}">
                    <f:attribute name="personalIdType" value="#{personModelBean.tgssPerson.tgssPersonalIdType}"/>
                    <f:attribute name="idPerson" value="#{personModelBean.tgssPerson.idPerson}"/>
                    <f:validator binding="#{personIdentifierValidator}"/>
                    <p:ajax disabled="#{personModelBean.tgssPerson.idPerson == null or personSimpleModelBean.fieldValidationError == null}"/>
                    <p:ajax event="blur" oncomplete="showDialogConditionally(args,'personDuplicatedDialog')"
                            update=":#{p:component('personDuplicatedDialog')}" process="@this"
                            disabled="#{personModelBean.tgssPerson.idPerson != null and personSimpleModelBean.fieldValidationError != null}"/>
</p:inputText>
rlopezo
  • 425
  • 5
  • 16
  • Did you read this: http://stackoverflow.com/questions/19712743/skip-required-validation-and-invoke-the-application – Kukeltje Aug 11 '16 at 09:35
  • Yes, but my field is always required, but I want to skip the required validation when the onblur event executes, and validate the required field only in the submit. – rlopezo Aug 11 '16 at 09:47
  • 1
    Uhhmmm... _"my field is **always required**, but I want to **skip the required validation** when the onblur event executes"_. Then it is not always required – Kukeltje Aug 11 '16 at 09:49
  • Yes, is required, but I want to skip the required validation when the onblur event occurs. I only want validate the required field on submit. – rlopezo Aug 11 '16 at 09:51
  • And a basic example on how to have a conditional required is in the link I posted. Yes it needs some adaptation (like detecting the right event) but the basics is there – Kukeltje Aug 11 '16 at 09:59
  • Yes you are right, actually my problem is that I don't know how to evaluate if my field is empty from the onblur event. The solution would be set disabled="#{fieldValue is empty}" inside p:ajax onblur declaration, but I don't know how to access to this value :(. – rlopezo Aug 11 '16 at 10:26
  • Your usecase is strange. If you have a field that is required (which means not empty) it must not be empty on transmission. Hooking the blur event and processing the field is indeed transmission. So this is a contradiction. What about simply making the field not required (in the sense of jsf), do validation and accept empty values when blur event occurs but strike out empty values when submitting in different ways (e.g. with a ``) by providing a custom error message instead of jsf required error message? – irieill Aug 11 '16 at 14:02

0 Answers0