On 5/4/2009 10:23 AM, joeygartin wrote:
> I would like to add a css class to form elements if there is an error
> in the form.  Not sure the BEST/EASIEST way to do this.  I would only
> want the attribute added if there was an error and I would like to do
> this in the cleanest way possible.  Meaning I would LIKE to stay away
> from if statements for every form element I have in the HTML and
> rather put the proper code in Python (perhaps forms.py with the form
> declaration), but I am new and not exactly sure how to proceed.

Once you've determined that your form didn't validate, something like 
this should work:

{{{
for field_name in form.errors:
     form.fields[field_name].widget.attrs['class'] = 'error'
}}}

Then just output your form again.

-- 
George

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to