diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index a2a99e104..c8e561d75 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -483,3 +483,56 @@ function prepareDeleteButtons(formLabel) { }, 50); } })(); + +function toggleTwoDomElements(ele1, ele2, index) { + let element1 = document.getElementById(ele1); + let element2 = document.getElementById(ele2); + if (element1 && element2) { + // Toggle display based on the index + element1.style.display = index === 1 ? 'block' : 'none'; + element2.style.display = index === 2 ? 'block' : 'none'; + } else { + console.error('One or both elements not found.'); + } +} + +/** + * An IIFE that listens to the other contacts radio form on DAs and toggles the contacts/no other contacts forms + * + */ +(function otherContactsFormListener() { + // Get the radio buttons + let radioButtons = document.querySelectorAll('input[name="other_contacts-has_other_contacts"]'); + + function handleRadioButtonChange() { + // Check the value of the selected radio button + let selectedValue = document.querySelector('input[name="other_contacts-has_other_contacts"]:checked').value; + + switch (selectedValue) { + case 'True': + console.log('Yes, I can name other employees.'); + toggleTwoDomElements('other-employees', 'no-other-employees', 1); + break; + + case 'False': + console.log('No (We\'ll ask you to explain why).'); + toggleTwoDomElements('other-employees', 'no-other-employees', 2); + break; + + default: + console.log('Nothing selected'); + toggleTwoDomElements('other-employees', 'no-other-employees', 0); + } + } + + // Add event listener to each radio button + if (radioButtons) { + radioButtons.forEach(function (radioButton) { + radioButton.addEventListener('change', handleRadioButtonChange); + }); + } + + // initiaize + handleRadioButtonChange(); +})(); + diff --git a/src/registrar/templates/application_no_other_contacts.html b/src/registrar/templates/application_no_other_contacts.html deleted file mode 100644 index 69217bfc1..000000000 --- a/src/registrar/templates/application_no_other_contacts.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends 'application_form.html' %} -{% load static field_helpers %} - -{% block form_fields %} - {% with attr_maxlength=1000 %} - {% input_with_errors forms.0.no_other_contacts_rationale %} - {% endwith %} -{% endblock %} diff --git a/src/registrar/templates/application_other_contacts.html b/src/registrar/templates/application_other_contacts.html index d07873608..7a901dfc5 100644 --- a/src/registrar/templates/application_other_contacts.html +++ b/src/registrar/templates/application_other_contacts.html @@ -21,42 +21,47 @@ {{ forms.0 }} {# forms.0 is a small yes/no form that toggles the visibility of "other contact" formset #} - {{ forms.1.management_form }} - {# forms.1 is a formset and this iterates over its forms #} - {% for form in forms.1.forms %} -