I've fixed this in my project by adding the following to the form.
{{{
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
for key, value in self.fields.items():
if value.required:
self.fields[key].widget.attrs['required'] = 'required'
}}}
Without this, the form posts to the server and fails validation, when it
can/should be handled client side first. The fact 'if value.required' can
be tested here leads me to believe this is a bug and should be default
behaviour.
--
Ticket URL: <https://code.djangoproject.com/ticket/34400>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
Comment:
The `required` attribute of widgets is set when the widget is
[https://github.com/django/django/blob/4b1bfea2846f66f504265cec46ee1fe94ee9c98b/django/forms/widgets.py#L264
rendered], not when the form is instantiated.
--
Ticket URL: <https://code.djangoproject.com/ticket/34400#comment:1>