Pezholio Pezholio - 1 year ago 82
Javascript Question

Bootstrap Typeahead - don't autoselect first item?

I'm using this fork of the Twitter Bootstrap typeahead library, which allows asynchronous data sources as well as onselect events. It's working really well for me so far, but when a user tabs out of the field (i.e. doesn't actively select a drop down entry), the onselect event is fired (which in my case, redirects the user to another page). Is there any way I can stop the onselect event being fired if a user doesn't click? Here's what I've got so far (in CoffeeScript):

$(document).ready ->
source: (typeahead, query) ->
url: "/inspections/search.json?name="+query
success: (data) =>
return_list = []
$(data.results.inspections).each ->
return_list.push("<span data-url='" + this.uri + "/edit'>" + + ", " + + "</span>")


onselect: (obj) =>
window.location.href = $(obj).attr("data-url")

Answer Source

In the end, I answered my own question, and put the adjustments in this Gist:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download