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() {
// 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) {
case 'True':

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()

View file

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