Created
          June 3, 2015 02:13 
        
      - 
      
- 
        Save aindong/526f9088afeb67220c5f to your computer and use it in GitHub Desktop. 
    Jquery UI autocomplete select extension
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | (function( $ ) { | |
| $.ui.autocomplete.prototype.options.autoSelect = true; | |
| $( ".ui-autocomplete-input" ).live( "blur", function( event ) { | |
| var autocomplete = $( this ).data( "autocomplete" ); | |
| if ( !autocomplete.options.autoSelect || autocomplete.selectedItem ) { return; } | |
| var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ); | |
| autocomplete.widget().children( ".ui-menu-item" ).each(function() { | |
| var item = $( this ).data( "item.autocomplete" ); | |
| if ( matcher.test( item.label || item.value || item ) ) { | |
| autocomplete.selectedItem = item; | |
| return false; | |
| } | |
| }); | |
| if ( autocomplete.selectedItem ) { | |
| autocomplete._trigger( "select", event, { item: autocomplete.selectedItem } ); | |
| } | |
| }); | |
| }( jQuery )); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment