mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-08 00:25:55 +02:00
Works in both browser and ios safari
This commit is contained in:
@@ -83,19 +83,34 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Store the original list of options in a variable
|
||||||
|
var originalOptions = {};
|
||||||
|
|
||||||
// Function to filter options in a select element
|
// Function to filter options in a select element
|
||||||
function filterOptions(id) {
|
function filterOptions(id) {
|
||||||
var input = document.getElementById(id + "Search");
|
var input = document.getElementById(id + "Search");
|
||||||
var filter = input.value.toUpperCase();
|
var filter = input.value.toUpperCase();
|
||||||
var select = document.getElementById(id);
|
var select = document.getElementById(id);
|
||||||
var options = select.getElementsByTagName("option");
|
var options = select.getElementsByTagName("option");
|
||||||
for (var i = 0; i < options.length; i++) {
|
|
||||||
var txtValue = options[i].textContent || options[i].innerText;
|
// If the original list of options for this select element hasn't been stored yet, store it
|
||||||
if (txtValue.toUpperCase().indexOf(filter) > -1) {
|
if (!originalOptions[id]) {
|
||||||
options[i].style.display = "";
|
originalOptions[id] = Array.from(options).map(option => option.value);
|
||||||
} else {
|
|
||||||
options[i].style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the select element
|
||||||
|
while (select.firstChild) {
|
||||||
|
select.removeChild(select.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate the select element with the filtered labels
|
||||||
|
originalOptions[id].forEach(label => {
|
||||||
|
if (label.toUpperCase().indexOf(filter) > -1) {
|
||||||
|
let option = document.createElement('option');
|
||||||
|
option.value = label;
|
||||||
|
option.text = label;
|
||||||
|
select.appendChild(option);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user