[Html-widget] Behavior of Callback

Carl Franks fireartist at gmail.com
Fri Oct 6 18:35:34 CEST 2006


It seems a useful feature, but I think I'd prefer display_errors() to
take a list of names, for greater flexibility.
It would make sense to have all elements which accept a list of names,
to support this feature.

Carl

On 06/10/06, Ted Carnahan <ted at tedcarnahan.com> wrote:
> We've gone ahead and added a display_errors attribute to CallbackOnce.
> This attribute allows you to specify the number of fields, counting from
> the beginning of the list given to the constraint, for which errors will
> be attached.  Patch is attached.
>
> We have changed our code to use this in a number of places - in fact,
> there were no places where we wanted something other than the first
> option in the list.  Perhaps this approach is wrong, and the error ought
> to be attached, by default at least, to only the first element in the
> constraint's list?
>
> Bogdan Lucaciu wrote:
>
> >this problem is true for any and equal as well.
> >
> The behavior for Any is probably right - highlight all of the missing
> fields if all of them are missing.  For equal, it also makes sense to
> highlight both - because otherwise, which one is right?  But for (most
> uses of?) CallbackOnce, the first field or two are the "important" ones
> and the rest of the fields are just helpers.
>
> - Ted Carnahan
> ted at tedcarnahan.com
>
>
> Index: Widget/Constraint/CallbackOnce.pm
> ===================================================================
> --- Widget/Constraint/CallbackOnce.pm   (revision 113)
> +++ Widget/Constraint/CallbackOnce.pm   (working copy)
> @@ -4,7 +4,7 @@
>  use strict;
>  use base 'HTML::Widget::Constraint';
>
> -__PACKAGE__->mk_accessors(qw/callback/);
> +__PACKAGE__->mk_accessors(qw/callback display_errors/);
>
>  *cb = \&callback;
>
> @@ -38,6 +38,13 @@
>
>  L</cb> is provided as an alias to L</callback>.
>
> +=head2 display_errors
> +
> +Arguments: integer
> +
> +The number of fields in this constraint, counting from the beginning, which
> +will have errors attached to them.  Optional, defaults to all.
> +
>  =head2 process
>
>  Overrides L<HTML::Widget::Constraint/"process"> to ensure L</validate> is
> @@ -56,9 +63,10 @@
>      my $results = [];
>
>      if ( $self->not ? $result : !$result ) {
> -        for my $name (@names) {
> +               my $count = $self->display_errors || scalar( @names );
> +        for (my $index = 0; $index < $count; $index++) {
>              push @$results, HTML::Widget::Error->new(
> -                { name => $name, message => $self->mk_message } );
> +                { name => $names[$index], message => $self->mk_message } );
>          }
>      }
>
>
>
> _______________________________________________
> Html-widget mailing list
> Html-widget at lists.rawmode.org
> http://lists.rawmode.org/cgi-bin/mailman/listinfo/html-widget
>
>
>



More information about the Html-widget mailing list