title: JQuery UI Autocomplete prevent backspace from searching
body: <p>When a user hits the backspace key the search is triggered. How can I prevent this from happening? I have tried the following code, but it appears to only work after the second time the backspace key is pressed.</p>
  
  <pre><code>var $cached_input = $("#myinput");
  
  $cached_input.autocomplete({
      autoFocus: true,
      delay: 700,
      open: function (event, ui) {
          $(this).autocomplete("widget")
           .find("ui-menu-item-alternate")
            .removeClass("ui-menu-item-alternate")
           .end()
           .find("li.ui-menu-item:odd a")
            .addClass("ui-menu-item-alternate");
      },
      source: function (request, response) {
          var params = { searchTerm: request.term }
  
          //ajax call made here to load the data...
      },
      minLength: minChars
  }).keydown(function (event) {
      if (event.keyCode == 8) {
          $cached_input.autocomplete("disable");
      } else {
          $cached_input.autocomplete("enable");
      }
  });
  </code></pre>
  
  <p><strong>Edit</strong>
  As a workaround I have implemented the following changes (comments next to each) and it seems to do the job. Still open to better solutions if they exist.</p>
  
  <pre><code>var $cached_input = $("#myinput");
  var performSearch = true; //added variable to determine if I should search
  
  $cached_input.autocomplete({
      autoFocus: true,
      delay: 700,
      open: function (event, ui) {
          $(this).autocomplete("widget")
           .find("ui-menu-item-alternate")
            .removeClass("ui-menu-item-alternate")
           .end()
           .find("li.ui-menu-item:odd a")
            .addClass("ui-menu-item-alternate");
      },
      source: function (request, response) {
          if (performSearch) { //check variable before performing search
              var params = { searchTerm: request.term }
  
              //ajax call made here to load the data...
          }
      },
      minLength: minChars
  }).keydown(function (event) {
      if (event.keyCode == 8) {
          performSearch = false; //do not perform the search
      } else {
          performSearch = true; //perform the search
      }
  });
  </code></pre>