Problem to style form fields with error

69 views
Skip to first unread message

Guido Luis Dalla Vecchia

unread,
Apr 24, 2024, 8:15:27 PMApr 24
to Django users
Hello! I'm building my first website with Django and I've been stuck for the past two months with a problem I can't figure out.
My website has a form with three fields that allow the user to input his first name, last name and email.
In my "forms.py" file, I've declared "clean" methods for each field, that add the "error" class to them if they don't pass the validation.
In my CSS file, I declared a rule that applies the "background-color: lightcoral" to all elements with the class ".error".
The problem is that, when I fill in the "last name" field with invalid data, the "first name" field gets marked as invalid too.
I've tried everything I could think of, and nothing has worked. It's driving me crazy!! Has anyone ever seen something like this?

Pleas help!!!

Ryan Nowakowski

unread,
Apr 25, 2024, 10:36:03 AMApr 25
to django...@googlegroups.com
Can you share some code snippets?

Guido Luis Dalla Vecchia

unread,
Apr 25, 2024, 6:39:38 PMApr 25
to Django users
Here I attach the relevant parts of the files "views.py", "index.html" and "forms.py" so you can check them out.

Thanks!

views.py
index3.html
forms.py
Reply all
Reply to author
Forward
0 new messages