Skip to content

Commit da505e6

Browse files
Christoffer KingsrudChristoffer Kingsrud
Christoffer Kingsrud
authored and
Christoffer Kingsrud
committed
Added prop 'suggestOnAllWords' which will enable suggestions on more than one input word in search hit(s).
1 parent 589b7d7 commit da505e6

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/components/VueInstant.vue

+31-4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
'showAutocomplete': {
8181
type: Boolean,
8282
default: true
83+
},
84+
'suggestOnAllWords': {
85+
type: Boolean,
86+
default: false
8387
}
8488
},
8589
data () {
@@ -384,10 +388,33 @@
384388
this.placeholderVal === '' && this.highlightedIndex !== 0
385389
},
386390
isSimilar (o) {
387-
if (o) {
388-
return o[this.suggestionAttribute]
389-
.toLowerCase()
390-
.startsWith(this.textVal.toLowerCase())
391+
if (o) {
392+
if ( this.suggestOnAllWords ) {
393+
var isMatch = false;
394+
var words = o[this.suggestionAttribute].split(" ");
395+
var textValWords = this.textVal.split(" ");
396+
if ( words.length > 0) {
397+
words.forEach(function(word) {
398+
if ( textValWords.length > 0) {
399+
textValWords.forEach(function(textValWord) {
400+
if (word.toLowerCase().startsWith(textValWord.toLowerCase())) {
401+
isMatch = true;
402+
}
403+
});
404+
}
405+
else if (word.toLowerCase().startsWith(this.textVal.toLowerCase())) {
406+
isMatch = true;
407+
}
408+
});
409+
return isMatch;
410+
}
411+
}
412+
413+
return o[this.suggestionAttribute]
414+
.toLowerCase()
415+
.startsWith(this.textVal.toLowerCase())
416+
417+
391418
}
392419
},
393420
isSameType (o) {

0 commit comments

Comments
 (0)