I have a form that utilizes choices argument from which I've created a formset. When the page containing the formset is rendered, the fields that uses choices argument display drop-down select widgets. The forms that are filled by the user have no errors. However, the forms that are NOT filled by the user have 'This field is required' errors for all other fields but the fields that used the select widget.
It appears that the select field's initial values is causing the form to be treated as half-filled form and thus the form validation process throws errors for the required fields that are not filled.
# Form:
class OwnerForm(forms.Form):
name = forms.CharField(label = 'Name', max_length = 20)
owner_entity = forms.ChoiceField(label = 'Owner Entity', choices = OWNER_ENTITIES)
num_of_shares = forms.DecimalField(label = 'Number of Shares' , min_value = 0.0, max_digits = 5, decimal_places = 2)
share_class = forms.ChoiceField(label = 'Share Class', choices = SHARE_CLASSES)
joined_date = forms.DateField(label = 'Joined Date', help_text = 'mm/dd/yyyy')
# View:
# In Get method:
OwnersFormSet = formset_factory(OwnerForm, extra = 5)
...
# In Post method:
the_owners_forms = OwnerFormSet(request.POST)
if not the_owners_forms.is_valid():
the_owners_forms_errors = the_owners_forms.errors
So, the question is how do I deal with this behavior so that the non-filled forms are not taken to be as hal-filled forms because of the initial value of the select method?