You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by niels <ni...@gmail.com> on 2005/12/27 16:19:48 UTC

validwhen problem in combination with RadioButton

Hi,

I want to validate a form:
company field may only be filled if the selected (by radiobutton)
addresstype is equal to CN

I try to do this via:
<form-validation>
<formset>
     <form name="addressForm">
        <field property="company" depends="validwhen">
            <arg0 key="error.company"/>
            <var>
                <var-name>test</var-name>
                <var-value>((*this* != null) and
(addressType=="CN"))</var-value>
            </var>
        </field>
     </form>
    </formset>
</form-validation>

without anyl uck..and cannot find any error messages in de log file.
Who can help me?

Re: validwhen problem in combination with RadioButton

Posted by Laurie Harper <la...@holoweb.net>.
niels wrote:
> Hi,
> 
> I want to validate a form:
> company field may only be filled if the selected (by radiobutton)
> addresstype is equal to CN
> 
> I try to do this via:
> <form-validation>
> <formset>
>      <form name="addressForm">
>         <field property="company" depends="validwhen">
>             <arg0 key="error.company"/>
>             <var>
>                 <var-name>test</var-name>
>                 <var-value>((*this* != null) and
> (addressType=="CN"))</var-value>
>             </var>
>         </field>
>      </form>
>     </formset>
> </form-validation>
> 
> without anyl uck..and cannot find any error messages in de log file.
> Who can help me?

As written, your validation rule will only pass when company has a value 
and  addressType is "CN". I think what you want is more like 
'((addressType == "CN") or (*this* == null))' -- in other words, company 
is valid if it's empty or if addressType is CN. Written this way, 
company can be left empty even if addressType is CN. If company is 
required when addressType is CN, the rule will be a bit more complicated.

L.


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