You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mon Cab <fu...@yahoo.com> on 2005/11/13 00:26:06 UTC
Problems with "validwhen"
I am trying to use validwhen to make sure that
validator only requires a valid State and Zip if the
country selected is "United States".
But I am getting required error messages from both
state and zip when the form is submitted without these
values.
I am using the following config for validator:
<field property="state"
depends="required,validwhen,mask">
<var>
<var-name>test</var-name>
<var-value>(country=="United States")</var-value>
</var>
<var>
<var-name>mask</var-name>
<var-value>^[A-Z]{2}$</var-value>
</var>
</field>
<field
property="zip"
depends="required,validwhen,mask">
<var>
<var-name>test</var-name>
<var-value>(country=="United States")</var-value>
</var>
<var>
<var-name>mask</var-name>
<var-value>^\d{5}$</var-value>
</var>
</field>
Is this wrong? What should I be doing here?
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problems with "validwhen"
Posted by Mon Cab <fu...@yahoo.com>.
Nice one. Thanks Lorie. It works now.
--- Laurie Harper <la...@holoweb.net> wrote:
> Mon Cab wrote:
> > I am trying to use validwhen to make sure that
> > validator only requires a valid State and Zip if
> the
> > country selected is "United States".
> >
> > But I am getting required error messages from both
> > state and zip when the form is submitted without
> these
> > values.
> >
> > I am using the following config for validator:
> >
> >
> > <field property="state"
> > depends="required,validwhen,mask">
> >
> > <var>
> > <var-name>test</var-name>
> > <var-value>(country=="United
> States")</var-value>
> > </var>
> > <var>
> > <var-name>mask</var-name>
> > <var-value>^[A-Z]{2}$</var-value>
> > </var>
> > </field>
> >
> > <field
> > property="zip"
> > depends="required,validwhen,mask">
> >
> > <var>
> > <var-name>test</var-name>
> > <var-value>(country=="United
> States")</var-value>
> > </var>
> >
> > <var>
> > <var-name>mask</var-name>
> > <var-value>^\d{5}$</var-value>
> > </var>
> > </field>
> >
> > Is this wrong? What should I be doing here?
>
> You've specified a 'required' validation rule, so
> you're saying the
> fields are always required. Remove the 'required'
> and change your test
> to '(country != "United States") or (*this* !=
> null)'. See the
> documentation on validwhen [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
>
>
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problems with "validwhen"
Posted by Laurie Harper <la...@holoweb.net>.
Mon Cab wrote:
> I am trying to use validwhen to make sure that
> validator only requires a valid State and Zip if the
> country selected is "United States".
>
> But I am getting required error messages from both
> state and zip when the form is submitted without these
> values.
>
> I am using the following config for validator:
>
>
> <field property="state"
> depends="required,validwhen,mask">
>
> <var>
> <var-name>test</var-name>
> <var-value>(country=="United States")</var-value>
> </var>
> <var>
> <var-name>mask</var-name>
> <var-value>^[A-Z]{2}$</var-value>
> </var>
> </field>
>
> <field
> property="zip"
> depends="required,validwhen,mask">
>
> <var>
> <var-name>test</var-name>
> <var-value>(country=="United States")</var-value>
> </var>
>
> <var>
> <var-name>mask</var-name>
> <var-value>^\d{5}$</var-value>
> </var>
> </field>
>
> Is this wrong? What should I be doing here?
You've specified a 'required' validation rule, so you're saying the
fields are always required. Remove the 'required' and change your test
to '(country != "United States") or (*this* != null)'. See the
documentation on validwhen [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
Re: Problems with "validwhen"
Posted by Mon Cab <fu...@yahoo.com>.
Neat...
Thanks Paul. I didn't realize that it was possible to
nest multiple conditional statements (I read: "Only
two items may be joined with and or or" in the
documentation - which I am now assuming means only two
items in any set of parens).
--- Paul Benedict <pa...@yahoo.com> wrote:
> Mon,
>
> There's two conditions here. The State and Zip are
> valid (not required) when... Always look at
> this as "valid" not "required"; you need to list out
> the conditions which will make the validation
> pass.
>
> [1] the country is "United States" and *this* is not
> null
> [2] the country is not "United States" and *this* is
> null
>
> (((*this* != null) && (country=="United States")) ||
> ((*this* == null) && (country!="United
> States")))
>
> Remember, all your conditions must be wrapped into a
> parent parantheses.
>
> --- Mon Cab <fu...@yahoo.com> wrote:
>
> >
> > I am trying to use validwhen to make sure that
> > validator only requires a valid State and Zip if
> the
> > country selected is "United States".
> >
> > But I am getting required error messages from both
> > state and zip when the form is submitted without
> these
> > values.
> >
> > I am using the following config for validator:
> >
> >
> > <field property="state"
> > depends="required,validwhen,mask">
> >
> > <var>
> > <var-name>test</var-name>
> > <var-value>(country=="United
> States")</var-value>
> > </var>
> > <var>
> > <var-name>mask</var-name>
> > <var-value>^[A-Z]{2}$</var-value>
> > </var>
> > </field>
> >
> > <field
> > property="zip"
> > depends="required,validwhen,mask">
> >
> > <var>
> > <var-name>test</var-name>
> > <var-value>(country=="United
> States")</var-value>
> > </var>
> >
> > <var>
> > <var-name>mask</var-name>
> > <var-value>^\d{5}$</var-value>
> > </var>
> > </field>
> >
> > Is this wrong? What should I be doing here?
> >
> >
> >
> >
> >
> >
> >
> >
> > __________________________________
> > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > http://mail.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> user-help@struts.apache.org
> >
> >
>
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
>
>
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problems with "validwhen"
Posted by Paul Benedict <pa...@yahoo.com>.
Mon,
There's two conditions here. The State and Zip are valid (not required) when... Always look at
this as "valid" not "required"; you need to list out the conditions which will make the validation
pass.
[1] the country is "United States" and *this* is not null
[2] the country is not "United States" and *this* is null
(((*this* != null) && (country=="United States")) || ((*this* == null) && (country!="United
States")))
Remember, all your conditions must be wrapped into a parent parantheses.
--- Mon Cab <fu...@yahoo.com> wrote:
>
> I am trying to use validwhen to make sure that
> validator only requires a valid State and Zip if the
> country selected is "United States".
>
> But I am getting required error messages from both
> state and zip when the form is submitted without these
> values.
>
> I am using the following config for validator:
>
>
> <field property="state"
> depends="required,validwhen,mask">
>
> <var>
> <var-name>test</var-name>
> <var-value>(country=="United States")</var-value>
> </var>
> <var>
> <var-name>mask</var-name>
> <var-value>^[A-Z]{2}$</var-value>
> </var>
> </field>
>
> <field
> property="zip"
> depends="required,validwhen,mask">
>
> <var>
> <var-name>test</var-name>
> <var-value>(country=="United States")</var-value>
> </var>
>
> <var>
> <var-name>mask</var-name>
> <var-value>^\d{5}$</var-value>
> </var>
> </field>
>
> Is this wrong? What should I be doing here?
>
>
>
>
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org