Skip to content

Commit

Permalink
Default primary contact field to True for first contact (#2648)
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Coffee <[email protected]>
  • Loading branch information
dorian-adams and JacobCoffee authored Dec 2, 2024
1 parent c68d9e4 commit 1da2a8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit 1da2a8a

Please sign in to comment.