You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Steve <sm...@neca.com> on 2003/03/19 15:27:04 UTC

1.1-rc1 and Validator

I have just recently begun to utilize the validator in our application
and had I simple question that I could not find an answer to searching
the archives.
I have a search form that a user can enter in 1..n criteria for
searching. In a simple case there are two input fields. The validation
should ensure that at least one of the fields are populated prior to
submitting the form. How would I configure my validation.xml for this
case? I currently have the following:

 <form name="TestSearchForm">
	<field
      	property="someCriteria"
            depends="required,minlength">
            <msg name="required" key="errors.required"/>
            <arg0 key="searchForm.someCriteria"/>
            <arg1 name="minlength" key="${var:minlength}"
resource="false"/>

            <var>
           	  <var-name>minlength</var-name>
              <var-value>5</var-value>
            </var>
      </field>
      <field property="otherCriteria"
                    depends="required">
		<msg name="required" key="errors.required"/>
            <arg0 key="searchForm.otherCriteria"/>
      </field>
 </form>

Which works exactly as you would expect requiring that both fields are
populated. Thanks.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: 1.1-rc1 and Validator

Posted by James Turner <tu...@blackbear.com>.
Check out the "requiredif" validator, you can use it with the NULL
condition to require one field if the other one is null.

James

> -----Original Message-----
> From: Steve [mailto:sms687@neca.com] 
> Sent: Wednesday, March 19, 2003 9:27 AM
> To: struts-user@jakarta.apache.org
> Subject: 1.1-rc1 and Validator
> 
> 
> I have just recently begun to utilize the validator in our 
> application and had I simple question that I could not find 
> an answer to searching the archives. I have a search form 
> that a user can enter in 1..n criteria for searching. In a 
> simple case there are two input fields. The validation should 
> ensure that at least one of the fields are populated prior to 
> submitting the form. How would I configure my validation.xml 
> for this case? I currently have the following:
> 
>  <form name="TestSearchForm">
> 	<field
>       	property="someCriteria"
>             depends="required,minlength">
>             <msg name="required" key="errors.required"/>
>             <arg0 key="searchForm.someCriteria"/>
>             <arg1 name="minlength" key="${var:minlength}" 
> resource="false"/>
> 
>             <var>
>            	  <var-name>minlength</var-name>
>               <var-value>5</var-value>
>             </var>
>       </field>
>       <field property="otherCriteria"
>                     depends="required">
> 		<msg name="required" key="errors.required"/>
>             <arg0 key="searchForm.otherCriteria"/>
>       </field>
>  </form>
> 
> Which works exactly as you would expect requiring that both 
> fields are populated. Thanks.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org