running-coder / jquery-typeahead

Javascript Typeahead (autocomplete) plugin with more than 50 options and callbacks.
http://www.runningcoder.org/jquerytypeahead/
MIT License
544 stars 121 forks source link

Search from beginning of string? #534

Closed turik97 closed 3 years ago

turik97 commented 3 years ago

Is it possible to configure search to make it catch data when matches the request from the beginning of a string?

turik97 commented 3 years ago

I made this simple filter to exclude items which are matched in the middle of a word and it works for me. It will match a string if it contains requested words (in the beginning or anywhere after a space)

function matchStringStart(string, line) { regex = new RegExp("(^| )" + string, 'giu'); if (line.match(regex) != null) return true; else return false; }

filter: function(item, displayKey) { if(matchStringStart(input.val(), displayKey)) return true; }