From 9523e7966e138610f9aa9783eee6eac40e77dcc2 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:54:35 -0600 Subject: [PATCH] Don't show button if there is nothing to reset --- src/registrar/assets/js/get-gov.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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");