Django formset doesn't validate Django formset doesn't validate django django

Django formset doesn't validate


Heh, I was having this exact same problem. The problem is that you're using a formset!! Formsets allow all fields in a form to be blank. If, however, you have 2 fields, and fill out only one, then it will recognize your required stuffs. It does this because formsets are made for "bulk adding" and sometimes you don't want to fill out all the extra forms on a page. Really annoying; you can see my solution here.


For each of the fields that are required, add an extra entry in the attrs parameter

    resident_status = forms.ChoiceField(widget=forms.Select(        attrs={'class': 'form-control', 'required': 'required'}), choices=President.RESIDENT_STATUS,        required=True)

As you can see, I maintain the required=True for django's form validation but specify 'required':'required' for the template to insist for the field be required.

Hope that helps.


Add 2 lines.

if request.method == 'POST':  def initial_form_count(self): return 10 # the number of forms  AlbumFormSet.initial_form_count = initial_form_count  formset = AlbumFormSet(request.POST, request.FILES)

Good luck!