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

@ -506,7 +506,11 @@ function toggleTwoDomElements(ele1, ele2, index) {
function handleRadioButtonChange() { function handleRadioButtonChange() {
// Check the value of the selected radio button // Check the value of the selected radio button
let selectedValue = document.querySelector('input[name="other_contacts-has_other_contacts"]:checked').value; // Attempt to find the radio button element that is checked
let radioButtonChecked = document.querySelector('input[name="other_contacts-has_other_contacts"]:checked');
// Check if the element exists before accessing its value
let selectedValue = radioButtonChecked ? radioButtonChecked.value : null;
switch (selectedValue) { switch (selectedValue) {
case 'True': case 'True':

View file

@ -571,12 +571,22 @@ class YourContactForm(RegistrarForm):
class OtherContactsYesNoForm(RegistrarForm): class OtherContactsYesNoForm(RegistrarForm):
has_other_contacts = forms.TypedChoiceField( def __init__(self, *args, **kwargs):
coerce=lambda x: x.lower() == 'true', 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=( choices=(
(True, "Yes, I can name other employees."), (True, "Yes, I can name other employees."),
(False, "No (We'll ask you to explain why).") (False, "No (We'll ask you to explain why).")
), ),
initial=default_value,
widget=forms.RadioSelect widget=forms.RadioSelect
) )

View file

@ -831,9 +831,9 @@ class DomainApplication(TimeStampedModel):
DomainApplication.OrganizationChoices.INTERSTATE, DomainApplication.OrganizationChoices.INTERSTATE,
] ]
def show_no_other_contacts_rationale(self) -> bool: def has_rationale(self) -> bool:
"""Show this step if the other contacts are blank.""" """Does this application have no_other_contacts_rationale"""
return not self.other_contacts.exists() return bool(self.no_other_contacts_rationale)
def has_other_contacts(self) -> bool: def has_other_contacts(self) -> bool:
"""Does this application have other contacts listed?""" """Does this application have other contacts listed?"""