diff --git a/sponsors/forms.py b/sponsors/forms.py index 4ced017c9..33b299322 100644 --- a/sponsors/forms.py +++ b/sponsors/forms.py @@ -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() diff --git a/sponsors/tests/test_forms.py b/sponsors/tests/test_forms.py index 49b0515cd..c375b9a2b 100644 --- a/sponsors/tests/test_forms.py +++ b/sponsors/tests/test_forms.py @@ -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):