On Feb 16, 10:12 am, "Brian Morton" <[EMAIL PROTECTED]> wrote:
> I don't know if this has been suggested yet, but has anyone considered an
> enhancement to newforms to optionally allow a field to have a different
> class if it has an error? It would be helpful for things like making error
> fields highlighted red, etc. Just a thought.
Yes that'd be nice, for sure. I guess we'd either set errors_css in
the class meta, or as an errors_css parameter when you create the form
object? Anybody has any preference let me know I'll get a diff
together :-)
In the meantime, some of you might be interested to explicitly set
field css classes. I couldn't find a way to do it yet, so here's a
diff below. Just set css='myclass' on your fields, eg
DateField(required=false, css='vDateField'). By the way, that example
there gives you nice little date pickers a la Django admin, when
combined with a couple of their javascripts.
--- fields.py Fri Feb 16 18:48:14 2007
+++ fields.py Fri Feb 16 18:47:30 2007
@@ -35,7 +35,7 @@
# Tracks each time a Field instance is created. Used to retain
order.
creation_counter = 0
- def __init__(self, required=True, widget=None, label=None,
initial=None, help_text=None):
+ def __init__(self, required=True, widget=None, label=None,
initial=None, help_text=None, css=None):
# required -- Boolean that specifies whether the field is
required.
# True by default.
# widget -- A Widget class, or instance of a Widget class,
that should be
@@ -60,6 +60,10 @@
extra_attrs = self.widget_attrs(widget)
if extra_attrs:
widget.attrs.update(extra_attrs)
+
+ # Allow a CSS class to be specified
+ if css:
+ widget.attrs.update({'class':css})
self.widget = widget
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" 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/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---