You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Pete Poulos <pe...@gmail.com> on 2009/08/23 03:50:24 UTC

Cross Field Validation

For cross field validation it would be nice if the Form object allowed
you to mark multiple fields with a single validation failure.
Currently, the only way I can see to do this is to either create two
validation errors, one for each field (so that they are decorated
properly).  However, if you are also using the <t:errors /> component,
then you end up with that validation failure showing up twice in the
errors list...

Something like the following (for a create new user form):

@InjectComponent
private Form form;

@InjectComponent
private PasswordField passwordField1, passwordField2;

@Property
private String password1, password2;

void onValidateForm() {
   if( password1 != null && !password1.equals( password2 ) ) {
      form.recordError( "Passwords do not match", passwordField1,
passwordField2 );
   }
}

Another alternative would be to simply mark the field as having an
error with a method like the following:

form.recordError( passwordField1 );

This would decorate the field, but since there's no text it wouldn't
be added to the errors list.  This wouldn't work well with the
javascript clientValidation though (which I disable, I think it's
ugly).

Have I overlooked something? Is there some other way to accomplish
this?  With the current implementation it seems like my only real
option is to use:

form.recordError( "Passwords do not match" );

and not decorate the fields at all...

Thanks,
Pete Poulos

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


Re: Cross Field Validation

Posted by Onno Scheffers <on...@piraya.nl>.
>
> Have I overlooked something? Is there some other way to accomplish
> this?  With the current implementation it seems like my only real
> option is to use:


Have you thought about creating a custom errors component that does a better
job at displaying equal error-messages for different components?That way you
keep Tapestry validation intact, the labels and fields still get a t-error
style assigned to them and you have control over what errors get displayed.

I personally prefer putting the error-messages directly after the field that
is in error. Especially if you have a lot of fields in your form. Check out
the demo-page for the jQuery validation plugin to see an example of this
type of cross-field password validation:
http://jquery.bassistance.de/validate/demo/

I have disabled client validation in Tapestry as well, since it mostly gets
in my way. I'm planning to use the jQuery validation plugin instead and I
have adopted the same style of reporting server-side validation errors
already by implementing a custom ValidationDecorator in Tapestry. See
http://piraya-blog.blogspot.com/2009/06/creating-custom-validationdecorator-for.html
.


regards,

Onno