One option is to use the field.errors logic to decide whether to wrap an error class around the input and then use descendent selectors to target the input element with CSS. (.error input { ... }).
On Feb 24, 4:10 pm, Pugglewuggle <pugglewug...@gmail.com> wrote: > Hi, > > I'm making a form and would like to use CSS classes to give fields > different styles based on validation events, i.e. error or not. I'm > using the following code as of now. > > {% for field in form %} > <tr> > {% if field.errors %} > <th>{{ field.label_tag }}</th> > {% else %} > <th>{{ field.label_tag }}</th> > {% endif %} > <td>{{ field }}</td> > <td>{{ field.errors|striptags }}</td> > </tr> > {% endfor %} > > Is there any way to give the <input> element that's created a class > tag? or other tags? Is there any way to prepopulate the value the > rendered element using the template language? I'm essentially trying > to create "pretty" and user friendly validation errors. > > Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.