You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by newton rutgers <ne...@hotmail.com> on 2003/11/13 20:40:07 UTC

conditional validation

Hello All,

Can i do the conditional validation. For example if i have a drop down and 
the default value is "Please select one". if user dosen't select anything. 
validation won't show that it is required field to select.
can anyone please help. Also how do i validation for radio button to see 
that user select something.

the entry in my validation.xml looks like this:

<field    property="product"
         	   depends="required,mask">
         	     <msg name="mask" key="myForm.product.maskmsg"/>
         	     <arg0 key="myForm.product.displayname"/>
         	         <var>
                       <var-name>mask</var-name>
                       <var-value>^\w+$</var-value>
                     </var>

         </field>


Thanks,
Newt

_________________________________________________________________
Concerned that messages may bounce because your Hotmail account is over 
limit? Get Hotmail Extra Storage! http://join.msn.com/?PAGE=features/es


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


Re: conditional validation

Posted by Laurie Harper <la...@holoweb.net>.
newton rutgers wrote:
> Hello All,
> 
> Can i do the conditional validation. For example if i have a drop down 
> and the default value is "Please select one". if user dosen't select 
> anything. validation won't show that it is required field to select.
> can anyone please help. Also how do i validation for radio button to see 
> that user select something.
> 
> the entry in my validation.xml looks like this:
> 
> <field    property="product"
>                depends="required,mask">
>                  <msg name="mask" key="myForm.product.maskmsg"/>
>                  <arg0 key="myForm.product.displayname"/>
>                      <var>
>                       <var-name>mask</var-name>
>                       <var-value>^\w+$</var-value>
>                     </var>
> 
>         </field>

Newt, sorry, just noticed your thread was hijacked and you never got an 
answer. What you're looking for to perform conditional validation is the 
'validwhen' validation rule [1]. For your dropdown select case you can 
just use 'required'. For the radio buttons, if they each have the same 
name 'required' will work there too. If the radio buttons each have a 
different name, you'll need to use 'validwhen' to construct a condition 
for each radio button that says it is valid if '(radio1 != null) or 
(radio2 != null) or ...'.

L.

[1] 
http://struts.apache.org/struts-doc-1.2.8/userGuide/dev_validator.html#validwhen


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