1 Reply Latest reply on Feb 2, 2010 8:57 PM by idyoshin

    Field validation on blur and on submit

      Hi all,
      I have a form containing a tax code field. For this field I need two kinds of validation:
      a) i want to check the syntax (the number of characters, position of numbers, etc.)
      b) i want to check if this code is already existent in my database
      The second validation requires much more time respect to the first, so the a) should occur on blur, while the second one on submit. How can do that?
      At present, I wrote a validator that is recalled by


      <h:inputText id="lastName" required="true" size="38" maxlength="16" value="#{personHome.instance.taxCode}"
                     converter="#{upperCaseConverter}"
                     style="text-transform:uppercase"
                     validator="taxcodeValidator"/>



      and the validation is on blur.


      Thanks in advance,


      F.


        • 1. Re: Field validation on blur and on submit
          idyoshin

          try the following. to your validator (hope that is SEAM-managed validator) add property boolean onBlur  = false;  and assuming your input text is decorated inside of some <div id="lastNameField" /> with messages add following:


          <h:inputText id="lastName" required="true" size="38" maxlength="16" value="#{personHome.instance.taxCode}"
                         converter="#{upperCaseConverter}"
                         style="text-transform:uppercase"
                         validator="taxcodeValidator">
          
              <a4j:support event="onblur" reRender="lastNameField">
                   <f:setPropertyActionListener value="#{true}" target="#{taxcodeValidator.onBlur}" />
              </a4j:support>
          
          </h:inputText>






          and inside of your taxcodeValidator create simple if which would run different validation, and don't forget to set onBlur=false before leaving validation method.


          Hope that would be helpful.


          Regards,


          Ilya Dyoshin