implemented text search of select inputs

This commit is contained in:
alejandro.campos@artica.es 2022-04-21 16:56:08 +02:00
parent b2ea3d1d7a
commit 0223dd27c7
1 changed files with 29 additions and 0 deletions

View File

@ -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();
}
});
});
};