#34400: ModelFormSet not adding 'required' to fields
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  DuraNathOG                         |
                   Type:  Bug        |         Status:  new
              Component:  Forms      |        Version:  4.0
               Severity:  Normal     |       Keywords:  form modelform
           Triage Stage:             |  modelformset
  Unreviewed                         |      Has patch:  0
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 When working with ModelFormSet, the <input> tag is not getting the
 'required' attribute by default.

 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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070186cbe670c2-ff83f67c-6908-4b45-b6f0-b11b0bfa4c0e-000000%40eu-central-1.amazonses.com.

Reply via email to