Twitter typeahaed.js - Change query source when certain characters are hit
NickName:Tom Freezers Ask DateTime:2015-06-11T10:06:09

Twitter typeahaed.js - Change query source when certain characters are hit

I'm using typeahead.js and would like to use a local array for the typeahead if the user has typed 3 or less characters, and then fall back onto a remote query if typing more than that. How can I implement an if statement in the source option of the typeahead? Below is my code now, but it's not working as intended. The source doesn't seem to like this method. When I call localTypeaheadData it doesn't get returned properly to the source.

var localTypeaheadData = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.whitespace,
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  local: localArray
});

$('#sitesearch').typeahead({
    minLength: 1,
},
{
    name: 'sitesearch',
    source: function (query, process) {
    if (query.length < 4) {
        return localTypeaheadData;
    } else {
        return remoteTypeaheadData;
    }
}

Copyright Notice:Content Author:「Tom Freezers」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30770378/twitter-typeahaed-js-change-query-source-when-certain-characters-are-hit

More about “Twitter typeahaed.js - Change query source when certain characters are hit” related questions

Twitter typeahaed.js - Change query source when certain characters are hit

I'm using typeahead.js and would like to use a local array for the typeahead if the user has typed 3 or less characters, and then fall back onto a remote query if typing more than that. How can I

Show Detail

Twitter search for anything from a certain source

The Twitter-search features the possibility to search for a source of tweet by using the parameter "source:" (e.g. source:tweetdeck). If I just search for that it complains about a missing query, ...

Show Detail

ValueError: Invalid characters in query string with twitter streaming API

I get ValueError: Invalid characters in query string error when i use the twitter streaming API to make the following query. search_query = u"emmy awards, ios 7" streaming_url = u"https://stream.

Show Detail

Trim Characters to Certain Count For Twitter iOS

I have a feeling this will be too wordy, but I'll do my best. My app has quotes built-in that change each day. Some of them are over 140 characters, but I would like to be able to share via Twitt...

Show Detail

Requests fail authorization when query string contains certain characters

I'm making requests to Twitter, using the OAuth1.0 signing process to set the Authorization header. They explain it step-by-step here, which I've followed. It all works, most of the time. Authoriza...

Show Detail

How to limit characters to be shared to twitter from WinJS app

I have created a Windows 8.1 application in WinJS and I have some HTML content that I am sharing. I have implemented sharing as per the MS sample app (http://code.msdn.microsoft.com/windowsapps/Sh...

Show Detail

Twitter query result returns only 15 tweets

I'm using the twitter api in java to query tweets containing certain hashtags. Example: Query query = new Query("%23superbowl since:2013-12-21"); QueryResult result; result = twitter.search(quer...

Show Detail

Hit a breakpoint when there is certain method in call stack

I want a breakpoint to be hit when there is a certain method in the call stack. Can I do this somehow with the Visual Studio debugger? I want to be sure my breakpoint will be hit when the code is ...

Show Detail

Change font of certain symbols and or characters

So basically like the question states I need to be able and change the font of certain characters and symbols in my HTML without affecting how it looks. Currently, the HTML uses the Gotham font and...

Show Detail

Zend_Services_Twitter, change the API Source name

I am sending tweets to Twitter via Zend_Service_Twitter. The tweets appear with a note "via API". I want to set the API Source with a different name, is there already a functionality within the Zend

Show Detail