public/libraries.js
function(e){
            // TAB - switch to another input
            if(e.which == 9){
              $newSelect.trigger('close');
              return;
            }

            // ARROW DOWN WHEN SELECT IS CLOSED - open select options
            if(e.which == 40 && !options.is(':visible')){
              $newSelect.trigger('open');
              return;
            }

            // ENTER WHEN SELECT IS CLOSED - submit form
            if(e.which == 13 && !options.is(':visible')){
              return;
            }

            e.preventDefault();

            // CASE WHEN USER TYPE LETTERS
            var letter = String.fromCharCode(e.which).toLowerCase(),
                nonLetters = [9,13,27,38,40];
            if (letter && (nonLetters.indexOf(e.which) === -1)) {
              filterQuery.push(letter);

              var string = filterQuery.join(''),
                  newOption = options.find('li').filter(function() {
                    return $(this).text().toLowerCase().indexOf(string) === 0;
                  })[0];

              if (newOption) {
                activateOption(options, newOption);
              }
            }

            // ENTER - select option and close when select options are opened
            if (e.which == 13) {
              var activeOption = options.find('li.selected:not(.disabled)')[0];
              if(activeOption){
                $(activeOption).trigger('click');
                if (!multiple) {
                  $newSelect.trigger('close');
                }
              }
            }

            // ARROW DOWN - move to next not disabled option
            if (e.which == 40) {
              if (options.find('li.selected').length) {
                newOption = options.find('li.selected').next('li:not(.disabled)')[0];
              } else {
                newOption = options.find('li:not(.disabled)')[0];
              }
              activateOption(options, newOption);
            }

            // ESC - close options
            if (e.which == 27) {
              $newSelect.trigger('close');
            }

            // ARROW UP - move to previous not disabled option
            if (e.which == 38) {
              newOption = options.find('li.selected').prev('li:not(.disabled)')[0];
              if(newOption)
                activateOption(options, newOption);
            }

            // Automaticaly clean filter query so user can search again by starting letters
            setTimeout(function(){ filterQuery = []; }, 1000);
          }
function(e){
            // TAB - switch to another input
            if(e.which == 9){
              $newSelect.trigger('close');
              return;
            }

            // ARROW DOWN WHEN SELECT IS CLOSED - open select options
            if(e.which == 40 && !options.is(':visible')){
              $newSelect.trigger('open');
              return;
            }

            // ENTER WHEN SELECT IS CLOSED - submit form
            if(e.which == 13 && !options.is(':visible')){
              return;
            }

            e.preventDefault();

            // CASE WHEN USER TYPE LETTERS
            var letter = String.fromCharCode(e.which).toLowerCase(),
                nonLetters = [9,13,27,38,40];
            if (letter && (nonLetters.indexOf(e.which) === -1)) {
              filterQuery.push(letter);

              var string = filterQuery.join(''),
                  newOption = options.find('li').filter(function() {
                    return $(this).text().toLowerCase().indexOf(string) === 0;
                  })[0];

              if (newOption) {
                activateOption(options, newOption);
              }
            }

            // ENTER - select option and close when select options are opened
            if (e.which == 13) {
              var activeOption = options.find('li.selected:not(.disabled)')[0];
              if(activeOption){
                $(activeOption).trigger('click');
                if (!multiple) {
                  $newSelect.trigger('close');
                }
              }
            }

            // ARROW DOWN - move to next not disabled option
            if (e.which == 40) {
              if (options.find('li.selected').length) {
                newOption = options.find('li.selected').next('li:not(.disabled)')[0];
              } else {
                newOption = options.find('li:not(.disabled)')[0];
              }
              activateOption(options, newOption);
            }

            // ESC - close options
            if (e.which == 27) {
              $newSelect.trigger('close');
            }

            // ARROW UP - move to previous not disabled option
            if (e.which == 38) {
              newOption = options.find('li.selected').prev('li:not(.disabled)')[0];
              if(newOption)
                activateOption(options, newOption);
            }

            // Automaticaly clean filter query so user can search again by starting letters
            setTimeout(function(){ filterQuery = []; }, 1000);
          }
function ( e ) { // TAB - switch to another input if ( e . which == 9 ) { $newSelect . trigger ( 'close' ) ; return ; } // ARROW DOWN WHEN SELECT IS CLOSED - open select options if ( e . which == 40 && ! options . is ( ':visible' ) ) { $newSelect . trigger ( 'open' ) ; return ; } // ENTER WHEN SELECT IS CLOSED - submit form if ( e . which == 13 && ! options . is ( ':visible' ) ) { return ; } e . preventDefault ( ) ; // CASE WHEN USER TYPE LETTERS var letter = String . fromCharCode ( e . which ) . toLowerCase ( ) , nonLetters = [ 9 , 13 , 27 , 38 , 40 ] ; if ( letter && ( nonLetters . indexOf ( e . which ) === - 1 ) ) { filterQuery . push ( letter ) ; var string = filterQuery . join ( '' ) , newOption = options . find ( 'li' ) . filter ( function ( ) { return $ ( this ) . text ( ) . toLowerCase ( ) . indexOf ( string ) === 0 ; } ) [ 0 ] ; if ( newOption ) { activateOption ( options , newOption ) ; } } // ENTER - select option and close when select options are opened if ( e . which == 13 ) { var activeOption = options . find ( 'li.selected:not(.disabled)' ) [ 0 ] ; if ( activeOption ) { $ ( activeOption ) . trigger ( 'click' ) ; if ( ! multiple ) { $newSelect . trigger ( 'close' ) ; } } } // ARROW DOWN - move to next not disabled option if ( e . which == 40 ) { if ( options . find ( 'li.selected' ) . length ) { newOption = options . find ( 'li.selected' ) . next ( 'li:not(.disabled)' ) [ 0 ] ; } else { newOption = options . find ( 'li:not(.disabled)' ) [ 0 ] ; } activateOption ( options , newOption ) ; } // ESC - close options if ( e . which == 27 ) { $newSelect . trigger ( 'close' ) ; } // ARROW UP - move to previous not disabled option if ( e . which == 38 ) { newOption = options . find ( 'li.selected' ) . prev ( 'li:not(.disabled)' ) [ 0 ] ; if ( newOption ) activateOption ( options , newOption ) ; } // Automaticaly clean filter query so user can search again by starting letters setTimeout ( function ( ) { filterQuery = [ ] ; } , 1000 ) ; }
Allow user to search by typing this array is cleared after 1 second
Allow user to search by typing this array is cleared after 1 second