Don't show button if there is nothing to reset

This commit is contained in:
zandercymatics 2024-08-12 10:54:35 -06:00
parent b59a624391
commit 9523e7966e
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -2045,6 +2045,13 @@ document.addEventListener('DOMContentLoaded', function() {
isTyping = false; 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 // Change the default input behaviour - have it reset to the data default instead
clearInputButton.addEventListener("click", (e) => { clearInputButton.addEventListener("click", (e) => {
if (overrideDefaultClearButton && initialValue) { 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) { function addBlankOption(clearInputButton, dropdownList, initialValue) {
if (dropdownList && !dropdownList.querySelector('[data-value=""]') && !isTyping) { if (dropdownList && !dropdownList.querySelector('[data-value=""]') && !isTyping) {
const blankOption = document.createElement("li"); const blankOption = document.createElement("li");