views:

20

answers:

1

First time I render a form I don't want the required error message to show up. Although if the field is left empty, it should prompt when submitting.

I know I can set an specific message and set it empty. But this way it never shows up:

error_messages = {'required':''}

I'm using a decorator to change label_tag behavior in BoundField, that makes an "*" show up next to the field label. But I need the error message to show up, only if field is empty.

I know I can check if field is required using:

{% if field.field.required %}

But I would need a way to know if the site is being rendered for the first time. For this I would like not to use an extra variable passed from the view or javascript. I have noticed that formsets actually work this way, but I don't want to put the form in a formset of one form

+1  A: 

Error messages don't show up the first time anyway, if you're following the correct pattern in your view.

I suspect the error is showing because you're instantiating the form with a data parameter. You shouldn't do this when you're displaying it on the first GET. The proper way to do it is shown in the documentation.

Daniel Roseman
I completely forgot the standard behavior after seeing errors prompting for the first time again and again. You are totally right and spotted it extremely fast. Thanks!
maraujop