Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sponsors/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ def __init__(self, *args, **kwargs):
if self.data:
self.contacts_formset = SponsorContactFormSet(self.data, **formset_kwargs)
else:
self.contacts_formset = SponsorContactFormSet(**formset_kwargs)
self.contacts_formset = SponsorContactFormSet(
initial=[{"primary": True}],
**formset_kwargs
)

def clean(self):
cleaned_data = super().clean()
Expand Down
9 changes: 9 additions & 0 deletions sponsors/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,15 @@ def test_invalidate_form_if_no_primary_contact(self):
msg = "You have to mark at least one contact as the primary one."
self.assertIn(msg, form.errors["__all__"])

def test_initial_primary_contact(self):
form = SponsorshipApplicationForm()
formset = form.contacts_formset

self.assertTrue(
formset.forms[0].initial.get("primary"),
"The primary field in the first contact form should be initially set to True."
)


class SponsorContactFormSetTests(TestCase):
def setUp(self):
Expand Down
Loading