diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 1d9caafde..d238823b3 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -2045,6 +2045,13 @@ document.addEventListener('DOMContentLoaded', function() { isTyping = false; }); + // Hide the reset button when there is nothing to reset. + // Do this once on init, then everytime a change occurs. + updateClearButtonVisibility(select, initialValue, clearInputButton) + select.addEventListener("change", () => { + updateClearButtonVisibility(select, initialValue, clearInputButton) + }); + // Change the default input behaviour - have it reset to the data default instead clearInputButton.addEventListener("click", (e) => { if (overrideDefaultClearButton && initialValue) { @@ -2066,6 +2073,14 @@ document.addEventListener('DOMContentLoaded', function() { }); } + function updateClearButtonVisibility(select, initialValue, clearInputButton) { + if (select.value === initialValue) { + hideElement(clearInputButton); + }else { + showElement(clearInputButton) + } + } + function addBlankOption(clearInputButton, dropdownList, initialValue) { if (dropdownList && !dropdownList.querySelector('[data-value=""]') && !isTyping) { const blankOption = document.createElement("li");