Hi Jason,

I don't quite get how your update_options is supposed to work (is it
called by options_for?) anyway that's how I will go to do what you're
trying to do:

Build a css_classes (maybe nested) dict by walking the error one and
replace all errors key values with the css class you need, then add
that one to the d["tg_options"] dict inside update_data, this should do
the trick.

Try that and let me know, if it works (and it should I hope ;-)) I'm
going to change tg_options to something more descriptive that enforces
the relationship with options_for, for example member_widgets_options
is good IMHO since we are already using member_widgets.

Ciao
Michele

Jason Chu wrote:
> Currently, the TableForm/ListForm widgets display error messages beside
> the widgets they apply to, but don't actually modify the widget itself.
>
> We really want to have error messages listed at the top of the form and
> red boxes around the widgets that have errors related to them.
>
> To list the columns with errors on them, we end up looping through
> cherrypy.request.validations_errors like this:
> <div
> py:for="i, error in getattr(cherrypy.request, 'validation_errors',
> {}).iteritems()" class="error">${i}: ${error}</div>
>
> I realize that if I have compound widgets error won't just be a string,
> but I don't have that case just yet.  If I run into that case, I'll
> probably create a dict similar to validation_errors with the proper
> column names and iterate over that instead of validation_errors.
>
> Now, to put red boxes around the form fields, you usually use css, but
> how do I add a css class to a widget when I don't want to do any
> processing in the template and my display function is of the form
> summary.display(value_for(summary), **options_for(summary))?
>
> It seems logical to do something to make options_for tell the widget
> about my new class.  I wrote something just like that, I called it
> update_options.  It looks something like this:
>
> def update_options(self, d, item, name, key, value):
>     path = widgets.path_from_item(item)
>     if len(path) is 0:
>         return None
>     else:
>         options = d['tg_options']
>         options = options.setdefault(name, {})
>         for p in path:
>             options = options.setdefault(p[0], {})
>         options[key] = value
>
> I've had to modify it once already, as a fix to the changes created by
> repeating widgets.
>
> Is this a good way to do what I want to do?  If it is, can I get an
> official version of update_options, so that I don't have to keep
> updating mine every time something related to widgets and options
> changes?
>
> Jason
>
> --=_mercury-3300-1143746172-0001-2
> Content-Type: application/pgp-signature
> Content-Transfer-Encoding: base64
> Content-Disposition: inline;
>       filename="signature.asc"
> X-Google-AttachSize: 192


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" 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-trunk
-~----------~----~----~----~------~----~------~--~---

Reply via email to