15👍
✅
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.
👤mpen
4👍
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.
- Django RequestFactory file upload
- Django 1.4 Unknown command: 'runserver'
- Logging Django SQL queries with DEBUG set to False
- How to test postgresql credentials from bash?
- How to display total record count against models in django admin
0👍
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!
- Select ForeignKey field in form ChoiceField
- Django: lock particular rows in table
- How do I get the content length of a Django response object?
- 'Suspicious Operation: Attempted access to "" denied' while loading static files
- Docker env variables not set while log via shell
- Cannot Log in to Django Admin Interface with Heroku Deployed App
- Django 'ManagementForm data is missing or has been tampered with' when saving modelForms with foreign key link
- DeleteView with a dynamic success_url dependent on id
- Filter a Django form select element based on a previously selected element
- How to programmatically generate celerybeat entries with celery and Django
Source:stackexchange.com