views:

26

answers:

1

Hi guys, my problem is simple. Where the right place for a custom error_css_class value is when using ModelForm?

I tried this:

class ToolForm(ModelForm):
error_css_class = 'wrong_list'
class Meta:
    model = Tool
    widgets = {
               'name' : TextInput(attrs={'class': 'small_input corners'}),
               'description' : Textarea(attrs={'cols': 20, 'rows': 5, 'class': 'text corners'}),
               'stocks' : TextInput(attrs={'class': 'small_input corners'}),
               'state' : Textarea(attrs={'cols': 25, 'rows': 6, 'class': 'text corners'}),
    }

Also, I tried as a class Meta value. Doesn't work either.

By now I just changed my css to 'errorlist' (u know, the default one), buuut this kind of doubts make me unhappy :P.

Any help is appreciated.

A: 

You can define your own error list class by inherting from django's ErrorList. See the docs for details:

Note that you'll have to override the method to output the full HTML and can't just replace CSS class. You could call the base method and do a string replace on "class=\"errolist\"" and return the output.

ars
Nice, I did that way, nevertheless I just wanted to change the css value, is there a way of changing that value directly?Thanks dude.
berserkpi
Unfortunately not -- it seems it's hard coded in the generated HTML: http://code.djangoproject.com/browser/django/trunk/django/forms/util.py#L36
ars