JAVASCRIPT   29
enterPress
Guest on 2nd February 2023 02:04:44 PM


  1.    function enterPress (e) {
  2.         var e = e || window.event;
  3.         var uid = $("#search_info").val();
  4.         uid = uid.replace(/^\s+|\s+$/g, "");
  5.         if (uid.length === 0) {
  6.             return false;
  7.         }
  8.         if (e.keyCode === 13) {
  9.             document.getElementById('search-form').submit()
  10.         }
  11.     }
  12.  
  13.     var states = new Bloodhound({
  14.         datumTokenizer: Bloodhound.tokenizers.whitespace,
  15.         queryTokenizer: Bloodhound.tokenizers.whitespace,
  16.         prefetch: '/js/typeahead/game-title.json'
  17.     });
  18.  
  19.     $('#search-form #search_info').typeahead(
  20.         {
  21.             hint: true,
  22.             highlight: true,
  23.             minLength: 1
  24.         },
  25.         {
  26.             name: 'states',
  27.             source: states,
  28.             limit: 10
  29.         }
  30.     ).bind('typeahead:select', function(ev, suggestion) {
  31.         $('#search-form').submit();
  32.     });

Raw Paste

Login or Register to edit or fork this paste. It's free.