I have this search function for a multiple select:
var SWAPLIST = {};
SWAPLIST.search = function(list, search) {
$(list)
.children()
.prop('selected', false)
.filter(function() {
if (!search)
{
return false;
}
return $(this)
.text()
.toLowerCase()
.indexOf(search.toLowerCase()) > - 1;
})
.prop('selected', true)
};
Bound it to this event:
$(document).ready(function(){
$('.entitySearch').keyup(function() {
var kind = $(this).attr('kind');
var left = '.leftEntities[kind=' + kind +']';
var right = '.rightEntities[kind='+ kind +']';
SWAPLIST.search(left + "," + right, $(this).val());
});
});
This is an example of my multiselect:
<select class="leftEntities grid5" kind="<?php echo $firstKeyLeft;?>" multiple="multiple" size="10">
<option> a </option>
<option> ab </option>
<option> abc </option>
<option> abcd </option>
</select>
This is my search input:
<div class="grid6 marginTop10px">
<input kind="<?php echo $firstKeyLeft;?>" class="entitySearch form-control-static" role="form" type="text" size="25"/>
<span class="glyphicon glyphicon-search"></span>
<label> Suchen </label>
</div>
And now I want to hide the options that don't match when I'm typing in the search key and of course unhide them when I remove or edit (so that it will match) the typed in search key.
Here the original relevant php and html code: http://codepad.org/4CXgkiei