In order to filter the checkboxes in the code below, I would like to only display the checkbox with a value matching the input entered in the input field with the class "js-filter-input". For example, if I type "uni1" in the input field, I want to show only the checkbox with the value of "uni1" and hide all other checkboxes. However, my current code is not functioning correctly.
$( document ).on( 'keyup', '.js-filter-input', function () {
var val;
var $content = $( this ).parent().next().find( ".search-filter-con" ).find( '.label-name' ).text() + " ";
if ( val = $( this ).val() ) {
$( '.group-checkbox .label-name', $content ).each( function () {
var patt = new RegExp( val, 'i' );
if ( patt.test( $( this ).data( 'en' ) ) || patt.test( $( this ).data( 'fa' ) ) || patt.test( $( this ).data( 'search' ) ) ) {
$( this ).parent().show();
} else {
$( this ).parent().hide();
}
});
} else {
$( '.group-checkbox', $content ).show();
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="search-container2">
<input class="search_box js-filter-input" placeholder="" name="" type="text">
<button value="" class="search_submit" name="search_submit" type="submit"><i class="fa fa-search"></i></button>
</div>
<div class="searchList">
<div class="sampleContainer mCustomScrollbar _mCS_3 mCS-dir-rtl mCS_no_scrollbar">
<div class="mCustomScrollBox mCS-light-thin mCSB_vertical mCSB_inside">
<div class="mCSB_container mCS_y_hidden mCS_no_scrollbar_y" dir="rtl">
<div class="search-filter-con">
<div class="group-checkbox">
<div class="squaredFour">
<input type="checkbox" value="None" id="uni1" name="check" />
<label for="uni1"></label>
</div>
<label class="label-name" for="uni1" data-fa="uni1" data-en="uni1" data-search="uni1>uni1</label>
</div>
<div class="group-checkbox">
<div class="squaredFour">
<input type="checkbox" value="None" id="uni2" name="check" />
<label for="uni2"></label>
</div>
<label class="label-name" for="uni2" data-fa="uni2" data-en="uni2" data-search="uni2">uni2</label>
</div>
</div>
</div>
</div>
</div>
</div>