From 0223dd27c7be69a5c23f1244700943d4bfde80f8 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 21 Apr 2022 16:56:08 +0200 Subject: [PATCH] implemented text search of select inputs --- pandora_console/include/javascript/pandora.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index b16373785f..d22068ae1e 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -2029,3 +2029,32 @@ function inArray(needle, haystack) { } return false; } + +/** + * Filter selector item by text based on a text input. + * + * @param {string} textbox Text input. + * + * @return {void} + */ +$.fn.filterByText = function(textbox) { + var select = this; + + $(textbox).bind("change keyup", function() { + var search = $.trim($(textbox).val()); + + $(select) + .find("option") + .each(function() { + if ( + $(this) + .text() + .includes(search.toLowerCase()) === true + ) { + $(this).show(); + } else { + $(this).hide(); + } + }); + }); +};