user3541631
user3541631

Reputation: 4008

Change the field class on error

I want to change the input field class and other attributes in case of error.

So in form init :

 for f_name in self.fields:
            if f_name in self.errors:
                self.fields[f_name].widget.attrs['error'] = a
            else:
                self.fields[f_name].widget.attrs['error'] = b

Now, I want to cycle thru the widget attributes and remove some attributes, not to be added to the html field(see error in this case).

{% for name, value in widget.attrs.items %}{% if name is not error %}{% if value is not False %} .....

the condition is not working:

{% if name is not error %}

I tried is not, != , is not in(error, alpha) also using error as string 'error'

are not working, but

{% if name == error %} is working

I don't understand why, because it should work as in normal python.

The value of error can variate.

Upvotes: 0

Views: 98

Answers (1)

wm3ndez
wm3ndez

Reputation: 723

It should be:

{% if name != 'error' %}

You are missing '', it's trying to compare it to another variable.

Upvotes: 1

Related Questions