You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Benny Law <be...@gmail.com> on 2009/10/19 23:10:56 UTC

Conditional Validators

Hi everyone,

I have a form with a field that is required only when certain conditions are
true, so I can't use validator="required" in the template. What is the best
way to handle this? I would rather not do it in onValidateForm because that
will require a duplicate error message to be provided (one that is already
provided by the required validator). Is there a way to dynamically add
validators to a field when a form is submitted before validations are
performed? I am using T5.1. Thanks.

Benny Law

Re: Conditional Validators

Posted by Benny Law <be...@gmail.com>.
Thanks for your comments, guys.

Benny

On Mon, Oct 19, 2009 at 7:39 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> This is actually a challenge in Tapestry. In effect, the component
> abstraction does get in the way of any kind of intra-field dependency,
> including validation. In simpler systems, you can create an
> "engineered coincidence" for these types of relationships ("the city
> field is required if a country is selected" is easier to implement if
> you have orchestrated that the client id and control names are "city"
> and "country" and directly connect to the "city" and "country"
> properties of the data object).  In Tapestry, a single form can
> reasonably edit many different data objects, and especially with loops
> and/or Ajax in the mix, the control names and client ids may vary
> wildly (including extra numbers to ensure that they are unique).
>
> I don't have a specific plan to address this; it may be something that
> is done less declaratively (using @Validate) and more imperatively (a
> set of utilities for generating the necessary client- and server-side
> validations).
>
> On Mon, Oct 19, 2009 at 2:57 PM, Ulrich Stärk <ul...@spielviel.de> wrote:
> > You can make form fields conditionally visible using the if or
> formfragment
> > components. Apart from that, manually performing validation in the
> > corresponding onValidate event handler method is the way to go.
> >
> > Uli
> >
> > Am 19.10.2009 23:10 schrieb Benny Law:
> >>
> >> Hi everyone,
> >>
> >> I have a form with a field that is required only when certain conditions
> >> are
> >> true, so I can't use validator="required" in the template. What is the
> >> best
> >> way to handle this? I would rather not do it in onValidateForm because
> >> that
> >> will require a duplicate error message to be provided (one that is
> already
> >> provided by the required validator). Is there a way to dynamically add
> >> validators to a field when a form is submitted before validations are
> >> performed? I am using T5.1. Thanks.
> >>
> >> Benny Law
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Conditional Validators

Posted by Howard Lewis Ship <hl...@gmail.com>.
This is actually a challenge in Tapestry. In effect, the component
abstraction does get in the way of any kind of intra-field dependency,
including validation. In simpler systems, you can create an
"engineered coincidence" for these types of relationships ("the city
field is required if a country is selected" is easier to implement if
you have orchestrated that the client id and control names are "city"
and "country" and directly connect to the "city" and "country"
properties of the data object).  In Tapestry, a single form can
reasonably edit many different data objects, and especially with loops
and/or Ajax in the mix, the control names and client ids may vary
wildly (including extra numbers to ensure that they are unique).

I don't have a specific plan to address this; it may be something that
is done less declaratively (using @Validate) and more imperatively (a
set of utilities for generating the necessary client- and server-side
validations).

On Mon, Oct 19, 2009 at 2:57 PM, Ulrich Stärk <ul...@spielviel.de> wrote:
> You can make form fields conditionally visible using the if or formfragment
> components. Apart from that, manually performing validation in the
> corresponding onValidate event handler method is the way to go.
>
> Uli
>
> Am 19.10.2009 23:10 schrieb Benny Law:
>>
>> Hi everyone,
>>
>> I have a form with a field that is required only when certain conditions
>> are
>> true, so I can't use validator="required" in the template. What is the
>> best
>> way to handle this? I would rather not do it in onValidateForm because
>> that
>> will require a duplicate error message to be provided (one that is already
>> provided by the required validator). Is there a way to dynamically add
>> validators to a field when a form is submitted before validations are
>> performed? I am using T5.1. Thanks.
>>
>> Benny Law
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Conditional Validators

Posted by Ulrich Stärk <ul...@spielviel.de>.
You can make form fields conditionally visible using the if or formfragment components. Apart from 
that, manually performing validation in the corresponding onValidate event handler method is the way 
to go.

Uli

Am 19.10.2009 23:10 schrieb Benny Law:
> Hi everyone,
> 
> I have a form with a field that is required only when certain conditions are
> true, so I can't use validator="required" in the template. What is the best
> way to handle this? I would rather not do it in onValidateForm because that
> will require a duplicate error message to be provided (one that is already
> provided by the required validator). Is there a way to dynamically add
> validators to a field when a form is submitted before validations are
> performed? I am using T5.1. Thanks.
> 
> Benny Law
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org