[Zope3-dev] Access to widget errors

Marius Gedminas mgedmin at b4net.lt
Thu Sep 9 11:44:15 EDT 2004


On Thu, Sep 09, 2004 at 10:14:51AM -0500, Garrett Smith wrote:
> Marius Gedminas wrote:
> > <http://dev.zope.org/Zope3/AccessToWidgetErrors>
> 
> Hi Marius,
> 
> It seems like you have these goals:
> 
> 1 - Flexibility in the way widget errors are rendered relative to
> (layout-wise) to their widgets
> 
> 2 - The ability to override a widget's error
> 
> 3 - You also mention object-level validation, though in passing
> 
> Re goal 1, you can skin the 'widget_row' macro (see its use in edit.pt
> and its default impl in widget_macros.pt) to override how
> labels/widgets/errors are handled. Perhaps this meets your need...if
> not, we might need some tweaking.

More tweaking is necessary.  I want to do something like this:

  <span class="error" tal:condition="widget/error"
        tal:attributes="title widget/error">!</span>

but I get

  <span class="error" title="&lt;span class=&quot;error&quot;&gt;Required input is missing.&lt;/span&gt;">!</span>

because widget/error returns HTML, and not just the error message.

I can do instead

  <span class="error" tal:condition="widget/error"
        tal:attributes="title widget/_error/doc">!</span>

but it is hackish.

> I'm unclear as to why you'd want to override _error, though.

Validation.

I have a form that has a N x 3 matrix of text widgets, where N varies
(the form is constructed dynamically).  The first of the three widgets
in every row contains an ID that must be unique.  When the form is
submitted, I want to see if there are any duplicates, and mark them.
Iin my opinion, it would be impolite to say to the user "there are
duplicates in the form, but I can't be bothered to point them out to
you, scan all 100 rows for yourself".  OK, I'm exaggerating a bit, the
actual number of rows is more like 4.

The field itself cannot perform the duplicate checking, because fields
are supposed to work in isolation, and therefore field validation cannot
take into account the values of other fields.

There are also other situations -- e.g. three related text widgets must
either all be empty, or must each contain a value.  If only one of the
three is valueless, I want that widget to indicate the error condition.

> Are you
> wanting to add marker interfaces for view lookup?

No.

> I guess before we open
> up _error in a public API we should be doubly sure its necessary (If
> this is a unique situation, could you subclass the widget and use it in
> a skin? You'd be looking at overriding getInputValue and configuring the
> error as needed.)

I do not think this is a unique situation.  There are cases where form
validation that needs to take more than one field into account.  This
can be solved by using schema constraints or writing custom view code.
I am trying to figure out how to report errors nicely, when this
cross-field validation fails.  In some cases it makes sense to display
an error message at the top (or bottom) of the whole form.  In other
cases it makes more UI sense to mark exactly which fields from a group
of validation-related fields are in error.

> As to goal 3, we will be implementing subscription based form validation
> (at some point...see Jim) as defined here:
> 
>   http://dev.zope.org/Zope3/NoMoreSchemaBinding

Consider the example from this wiki page:

  Suppose we have two fields, `max` and `min`. We want to assure that
  the `max` field value is not less than the `min` field value.

When a subscription based form validator finds out that `max` is less
than `min`, it should be able to cause the `max` widget to say so, when
the widget is rendered.

Marius Gedminas
-- 
If all else fails, read the documentation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-dev/attachments/20040909/bd647c78/attachment-0001.bin


More information about the Zope3-dev mailing list