From 9cb3ecebf4952c9779bc444ce9fb2e742d3cbf2e Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:08:00 -0700 Subject: [PATCH] Cleanup js after merge --- .../src/js/getgov-admin/domain-request-form.js | 15 +++++++++++++-- .../helpers-portfolio-dynamic-fields.js | 12 +++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/registrar/assets/src/js/getgov-admin/domain-request-form.js b/src/registrar/assets/src/js/getgov-admin/domain-request-form.js index 242ae25c8..928495cb6 100644 --- a/src/registrar/assets/src/js/getgov-admin/domain-request-form.js +++ b/src/registrar/assets/src/js/getgov-admin/domain-request-form.js @@ -629,7 +629,18 @@ export function initRejectedEmail() { }); } -function handleSuborganizationSelection() { + +/** + * A function that handles the suborganzation and requested suborganization fields and buttons. + * - Fieldwise: Hooks to the sub_organization, suborganization_city, and suborganization_state_territory fields. + * On change, this function checks if any of these fields are not empty: + * sub_organization, suborganization_city, and suborganization_state_territory. + * If they aren't, then we show the "clear" button. If they are, then we hide it because we don't need it. + * + * - Buttonwise: Hooks to the #clear-requested-suborganization button. + * On click, this will clear the input value of sub_organization, suborganization_city, and suborganization_state_territory. +*/ +function handleSuborgFieldsAndButtons() { const requestedSuborganizationField = document.getElementById("id_requested_suborganization"); const suborganizationCity = document.getElementById("id_suborganization_city"); const suborganizationStateTerritory = document.getElementById("id_suborganization_state_territory"); @@ -672,6 +683,6 @@ export function initDynamicDomainRequestFields(){ const domainRequestPage = document.getElementById("domainrequest_form"); if (domainRequestPage) { handlePortfolioSelection(); - handleSuborganizationSelection(); + handleSuborgFieldsAndButtons(); } } diff --git a/src/registrar/assets/src/js/getgov-admin/helpers-portfolio-dynamic-fields.js b/src/registrar/assets/src/js/getgov-admin/helpers-portfolio-dynamic-fields.js index 91fd2b6e3..ce5db34c1 100644 --- a/src/registrar/assets/src/js/getgov-admin/helpers-portfolio-dynamic-fields.js +++ b/src/registrar/assets/src/js/getgov-admin/helpers-portfolio-dynamic-fields.js @@ -471,6 +471,16 @@ export function handlePortfolioSelection( if (suborganizationCity) showElement(suborganizationCity); if (suborganizationStateTerritory) showElement(suborganizationStateTerritory); + // Handle rejectSuborganizationButtonFieldset (display of the clear requested suborg button). + // Basically, this button should only be visible when we have data for suborg, city, and state_territory. + // The function handleSuborgFieldsAndButtons() in domain-request-form.js handles doing this same logic + // but on field input for city, state_territory, and the suborg field. + // If it doesn't exist, don't do anything. + if (!rejectSuborganizationButtonFieldset){ + console.warn("updateSuborganizationFieldsDisplay() => Could not update rejectSuborganizationButtonFieldset") + return; + } + // Initially show / hide the clear button only if there is data to clear let requestedSuborganizationField = document.getElementById("id_requested_suborganization"); let suborganizationCity = document.getElementById("id_suborganization_city"); @@ -489,7 +499,7 @@ export function handlePortfolioSelection( if (requestedSuborganizationField) hideElement(requestedSuborganizationField); if (suborganizationCity) hideElement(suborganizationCity); if (suborganizationStateTerritory) hideElement(suborganizationStateTerritory); - hideElement(rejectSuborganizationButtonFieldset); + if (rejectSuborganizationButtonFieldset) hideElement(rejectSuborganizationButtonFieldset); } }