Skip to content

Commit af2493f

Browse files
committed
showing first the starts with matchs then the contains matches.
1 parent 98c0981 commit af2493f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

input-autocomplete-behavior.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@
484484
}
485485

486486
var patt = new RegExp( this._scapeString( term.toLowerCase() ) );
487+
var matchedStartsWith = [];
488+
var matchedContains = [];
487489
var matched = [];
488490
var candidates = this.localCandidates;
489491
var noSuggestInactive = Boolean(this.noSuggestInactive);
@@ -493,16 +495,28 @@
493495
var candidate = candidates[i];
494496
if (noSuggestInactive) {
495497
if (!Boolean(candidate.inactive)) {
498+
if( candidate.text.toLowerCase().startsWith(term.toLowerCase()) ){
499+
matchedStartsWith.push(candidate);
500+
}
501+
496502
if (patt.test(candidate.text.toLowerCase()) == true){
497-
matched.push(candidate);
503+
matchedContains.push(candidate);
498504
}
499505
}
500506
} else {
507+
if( candidate.text.toLowerCase().startsWith(term.toLowerCase()) ){
508+
matchedStartsWith.push(candidate);
509+
}
510+
501511
if (patt.test(candidate.text.toLowerCase()) == true){
502-
matched.push(candidate);
512+
matchedContains.push(candidate);
503513
}
504514
}
505515
}
516+
517+
matched = matchedStartsWith.concat(matchedContains).filter(function(item, pos, self) {
518+
return self.indexOf(item) == pos;
519+
});
506520
}
507521

508522
if (typeof(this._prefetchedCandidates) !== 'undefined'){

0 commit comments

Comments
 (0)