File tree Expand file tree Collapse file tree 2 files changed +12
-28
lines changed
Expand file tree Collapse file tree 2 files changed +12
-28
lines changed Original file line number Diff line number Diff line change 11var countries = {
22 "AD" : "Andorra" ,
3+ "A2" : "Andorra Test" ,
34 "AE" : "United Arab Emirates" ,
45 "AF" : "Afghanistan" ,
56 "AG" : "Antigua and Barbuda" ,
Original file line number Diff line number Diff line change 464464 var that = this ,
465465 options = that . options ,
466466 value = that . el . val ( ) ,
467- query = that . getQuery ( value ) ,
468- index ;
467+ query = that . getQuery ( value ) ;
469468
470469 if ( that . selection && that . currentValue !== query ) {
471470 that . selection = null ;
477476 that . selectedIndex = - 1 ;
478477
479478 // Check existing suggestion for the match before proceeding:
480- if ( options . triggerSelectOnValidInput ) {
481- index = that . findSuggestionIndex ( query ) ;
482- if ( index !== - 1 ) {
483- that . select ( index ) ;
484- return ;
485- }
479+ if ( options . triggerSelectOnValidInput && that . isExactMatch ( query ) ) {
480+ that . select ( 0 ) ;
481+ return ;
486482 }
487483
488484 if ( query . length < options . minChars ) {
492488 }
493489 } ,
494490
495- findSuggestionIndex : function ( query ) {
496- var that = this ,
497- index = - 1 ,
498- queryLowerCase = query . toLowerCase ( ) ;
491+ isExactMatch : function ( query ) {
492+ var suggestions = this . suggestions ;
499493
500- $ . each ( that . suggestions , function ( i , suggestion ) {
501- if ( suggestion . value . toLowerCase ( ) === queryLowerCase ) {
502- index = i ;
503- return false ;
504- }
505- } ) ;
506-
507- return index ;
494+ return ( suggestions . length === 1 && suggestions [ 0 ] . value . toLowerCase ( ) === query . toLowerCase ( ) ) ;
508495 } ,
509496
510497 getQuery : function ( value ) {
668655 category = currentCategory ;
669656
670657 return '<div class="autocomplete-group"><strong>' + category + '</strong></div>' ;
671- } ,
672- index ;
658+ } ;
673659
674- if ( options . triggerSelectOnValidInput ) {
675- index = that . findSuggestionIndex ( value ) ;
676- if ( index !== - 1 ) {
677- that . select ( index ) ;
678- return ;
679- }
660+ if ( options . triggerSelectOnValidInput && that . isExactMatch ( value ) ) {
661+ that . select ( 0 ) ;
662+ return ;
680663 }
681664
682665 // Build suggestions inner HTML:
You can’t perform that action at this time.
0 commit comments