handled form initialization

This commit is contained in:
David Kennedy 2024-01-04 06:36:20 -05:00
parent 98ad54bb01
commit 2e737bf4d8
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
3 changed files with 26 additions and 12 deletions

View file

@ -571,14 +571,24 @@ class YourContactForm(RegistrarForm):
class OtherContactsYesNoForm(RegistrarForm):
has_other_contacts = forms.TypedChoiceField(
coerce=lambda x: x.lower() == 'true',
choices=(
(True, "Yes, I can name other employees."),
(False, "No (We'll ask you to explain why).")
),
widget=forms.RadioSelect
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.application and self.application.has_other_contacts():
default_value = True
elif self.application and self.application.has_rationale():
default_value = False
else:
default_value = None
self.fields['has_other_contacts'] = forms.TypedChoiceField(
coerce=lambda x: x.lower() == 'true' if x is not None else None,
choices=(
(True, "Yes, I can name other employees."),
(False, "No (We'll ask you to explain why).")
),
initial=default_value,
widget=forms.RadioSelect
)
def is_valid(self):
val = super().is_valid()