Formset Initial Choice Field
I have a form (working correctly) which I want to pass to a Formset, but the tuples Im passing for the ChoiceFields are not rendered or have a error: This is the original form: cla
Solution 1:
You are passing the instance of the form instead of the form class to the formset_factory
method. You can set the choices after instantiating the formset.
forms.py:
class PO_Form(forms.Form):
base_item = forms.ChoiceField(choices=(), required=True)
color_or_print = forms.ChoiceField(choices=(), required=True)
material = forms.ChoiceField(choices=(), required=True)
size_group = forms.ChoiceField(choices=(), required=True)
views.py:
PO_FormSet = formset_factory(PO_Form)
formset = PO_FormSet()
for form in formset.forms:
form.fields['base_item'].choices = baseItem_choices
form.fields['color_or_print'].choices = color_choices
form.fields['material'].choices = material_choices
form.fields['size_group'].choices = sizeGroup_choices
Post a Comment for "Formset Initial Choice Field"