You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jay Burgess <li...@vtgroup.com> on 2005/11/07 22:22:57 UTC

Conditional validation

I have a form field on my JSP that's being conditionally displayed based on the
status of servlet context attribute:

<logic:equal name="mode" value="<%=Globals.REQUIRED%>">
    <html:text property="myField" size="15" />
</logic:equal>

I'm using the Struts validator to validate this field:

<field property="myField" depends="required,mask,maxlength">
...
</field>

Obviously, I only want the client-side Javascript validations to fire if the
field is present.  

Is there a way in VALIDATION.XML to conditionally include/exclude the Javascript
validations, so they don't fire if the field isn't present?  (They're currently
firing and failing, stopping the other client-side validations as well.)

Thanks.

Jay

| Vertical Technology Group
| http://www.vtgroup.com/




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


Re: Conditional validation

Posted by Laurie Harper <la...@holoweb.net>.
Jay Burgess wrote:
> I have a form field on my JSP that's being conditionally displayed based on the
> status of servlet context attribute:
> 
> <logic:equal name="mode" value="<%=Globals.REQUIRED%>">
>     <html:text property="myField" size="15" />
> </logic:equal>
> 
> I'm using the Struts validator to validate this field:
> 
> <field property="myField" depends="required,mask,maxlength">
> ...
> </field>
> 
> Obviously, I only want the client-side Javascript validations to fire if the
> field is present.  
> 
> Is there a way in VALIDATION.XML to conditionally include/exclude the Javascript
> validations, so they don't fire if the field isn't present?  (They're currently
> firing and failing, stopping the other client-side validations as well.)

Well, you've declared the field as 'required', so it's being, er, 
required... Remove the 'required' rule and, if you want to still make it 
required in some circumstances, use the validwhen rule [1].

L.

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


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