UnKnown UnKnown - 1 month ago 9
jQuery Question

How to make autocomplete backspace work in this case

As User types in the input i am searching the table and displaying results accordingly .

I have put up a condition to check , if the length of the entered input is at least greater than or equal to 2 .(but after clearing the values its not showing up all values ??)

This is my code

$('#searchequip').keyup(function (){
if ($(this).val().length >= 2) {
$('#errmsgnoequip').hide();
var val = $.trim(this.value).toUpperCase();
var noElem = true;
$('.mt-checkbox').each(function (){
var parent = $(this).closest('li'),
length = $(this).text().length > 0;
if (length && $(this).text().search(new RegExp(val, 'i')) < 0)
{
parent.fadeOut('slow');
} else {
noElem = false;
parent.show();
}
});
if (noElem)
$('#errmsgnoequip').html('No Results Matched').show();
}
});


http://jsfiddle.net/e08o7uct/34/

Answer

There is small change in your code, below code will work

$('#searchequip').keyup(function (){
if ($(this).val().length >= 2) {
    $('#errmsgnoequip').hide();
  var val = $.trim(this.value).toUpperCase();
  var noElem = true;
  $('.mt-checkbox').each(function (){
    var parent = $(this).closest('li'),
    length = $(this).text().length > 0;
    if (length && $(this).text().search(new RegExp(val, 'i')) < 0)
    {
      parent.fadeOut('slow');
    }else{
      noElem = false;
      parent.show();
    }
  });
  if (noElem)
    $('#errmsgnoequip').html('No Results Matched').show();
    } else {
        $("#equipdetails li").show();
    }
})