kerinin wrote:
> The 'standard' form widgets display text showing when their content
> doesn't validate properly. If I was to write my own widget from
> scratch and wanted to have a similar behavior, how would I do so? The
> link to error handling on the wiki assumes you're using the existing
> widgets and doesn't (unless i missed it) cover how to build the
> automatic behavior into widgets.
There is nothing different for custom widgets. You just add a validator
to the widget class or set it when you instantiate the widget.
> On a related note - is it possible to change how the standard widgets
> respond to validation errors? For instance, instead of displaying the
> text next to the form element, what if I wanted to change the
> element's background color and display an image of a stop sign next to
> the form element? Could I use a different color and image depending
> on what type of validation error it was?
You only need to overwrite the templatew of the standard widgets to do
that. Replace the line
<span py:if="error_for(field)" class="fielderror"
py:content="error_for(field)" />
with anything you want. E.g.
<img py:if="error_for(field)" src="${tg.url('static/images/error.gif')}"
alt="${error_for(field)}" />
For differentiating between different errors, you can evaluate
error_for(field). However, these are usually text messages which may
vary depending on the locale. But again, you can overwrite the messages
with something different that is not translated, e.g. error numbers
which are evaluated in the template, or already the appropriate
background color or file name of an error image.
-- Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---