Skip to content

Commit

Permalink
Cleanup js after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
zandercymatics committed Dec 20, 2024
1 parent cda7316 commit 9cb3ece
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/registrar/assets/src/js/getgov-admin/domain-request-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -672,6 +683,6 @@ export function initDynamicDomainRequestFields(){
const domainRequestPage = document.getElementById("domainrequest_form");
if (domainRequestPage) {
handlePortfolioSelection();
handleSuborganizationSelection();
handleSuborgFieldsAndButtons();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 9cb3ece

Please sign in to comment.