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 1
1
var countries = {
2
2
"AD" : "Andorra" ,
3
+ "A2" : "Andorra Test" ,
3
4
"AE" : "United Arab Emirates" ,
4
5
"AF" : "Afghanistan" ,
5
6
"AG" : "Antigua and Barbuda" ,
Original file line number Diff line number Diff line change 464
464
var that = this ,
465
465
options = that . options ,
466
466
value = that . el . val ( ) ,
467
- query = that . getQuery ( value ) ,
468
- index ;
467
+ query = that . getQuery ( value ) ;
469
468
470
469
if ( that . selection && that . currentValue !== query ) {
471
470
that . selection = null ;
477
476
that . selectedIndex = - 1 ;
478
477
479
478
// 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 ;
486
482
}
487
483
488
484
if ( query . length < options . minChars ) {
492
488
}
493
489
} ,
494
490
495
- findSuggestionIndex : function ( query ) {
496
- var that = this ,
497
- index = - 1 ,
498
- queryLowerCase = query . toLowerCase ( ) ;
491
+ isExactMatch : function ( query ) {
492
+ var suggestions = this . suggestions ;
499
493
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 ( ) ) ;
508
495
} ,
509
496
510
497
getQuery : function ( value ) {
668
655
category = currentCategory ;
669
656
670
657
return '<div class="autocomplete-group"><strong>' + category + '</strong></div>' ;
671
- } ,
672
- index ;
658
+ } ;
673
659
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 ;
680
663
}
681
664
682
665
// Build suggestions inner HTML:
You can’t perform that action at this time.
0 commit comments