[Html-widget] Behavior of Callback

Carl Franks fireartist at gmail.com
Wed Oct 18 14:56:15 CEST 2006


On 09/10/06, Ted Carnahan <ted at tedcarnahan.com> wrote:
> Here is a preliminary patch, targeted at Any, Equal, and CallbackOnce.
> One note - we change the behavior for Equal so that the default is to
> put an error message on all of the items if the constraint fails instead
> of assuming the first one always correct.  That may or may not be
> desirable - we think it a more sensible default.

I've been experimenting with this, and I'm not happy with the current
coupling of element values and constraint error display. The problem
isn't with your patch, it's the existing internals.

With your patch...
$w->element( Textfield => 'foo' );
$w->element( Textfield => 'bar' );
$w->constraint( Equal => 'foo', 'bar' );
If the values for 'foo' and 'bar' differ, 'foo and 'bar' both get an
error, and both $r->valid('foo') and $r->valid('bar') return false.

However, I don't like the error displaying on both elements, as I
usually set my own error message which explains what's wrong and it's
unnecessary to display it twice.

But, if I add $constraint->display_errors('foo'), now only 'foo' gets
an error, and worse, $r->valid('bar') is now true.

What I propose is that display_errors() instead sets a flag on an
$error, stating that it shouldn't be rendered.
This way, regardless of the value of display_errors(), both 'foo' and
'bar' will always get an error, and $r->valid('foo') and
$r->valid('bar') will both always return false.

I will also implement it such that all elements inherit the
display_errors() method, and the checking is in Widget.pm, instead of
in each constraint. This gives the advantages of simpler constraint
code, it can be set on any constraint, and you could also do something
such as $error->no_render(1) on errors retrieved from the result
object.

Does that sound good?

Carl



More information about the Html-widget mailing list