struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <lau...@holoweb.net>
Subject Re: Validator - how to check a checkbox
Date Mon, 14 Nov 2005 23:54:23 GMT
David Bolsover wrote:
> Hi all
> 
> I've done a deal of searching through the archives, looked at the examples -
> even read the docs - I'm still stuggling with this...
> 
> I need to validate a number of fields in a from; certain fields are required
> if a checkbox is checked and should be empty if the checkbox is not checked.
> 
> What is the correct syntax in validator.xml?
> 
> 'date_Shipped' must only be populated if the 'complete' checkbox is checked.
> 
> As an example of what I have tried....broken...
> 
> <field property="date_Shipped" depends="validwhen">
>  <arg0 key="returns.date_Shipped"/>
>    <var>
>     <var-name>test</var-name>
>     <var-value>(complete == 'on')</var-value>
>    </var>
> </field>

That says date_Shipped is valid *only* when complete has the value 'on'. 
And since a checkbox field is never going to have the value 'on', 
date_Shipped isn't ever going to be valid...

What you want is probably something like

    (((complete == false) and (*this* == null)) or
     ((complete == true)  and (*this* != null)))

I'm not sure if true/false is what you need, or if that needs to be a 
test for null; it probably depends on the type you've declared for the 
'complete' property in your form.

L.


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


Mime
View raw message