I'm trying to get the selected value of a typeahead input and I get this error every time: Uncaught TypeError: Cannot assign to read only property 'highlight' of
. It never tells me what object it's referring to and it originates from within the TypeAhead.min.js file, so I can't say exactly what line of my code is causing it. Here's the code I use to set up and capture the value of the input:
$(".articles.new").ready ->
engine = new Bloodhound {
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: autocomplete_items
}
engine.initialize()
$('#auto_complete').typeahead { hint: true, highlight: true, minLength: 1 },
{ name: "names", displayKey: "name", source: engine.ttAdapter()}
$('#auto_complete').on 'typeahead:selected', (event, selection) ->
alert selection.name
$('#auto_complete').typeahead 'setQuery', ''
event.stopPropagation()
return
return
For context: auto_complete items is an array of objects from my controller with name property. I'm working in Ruby on Rails 4.1.4.
What can I do to fix this error? What is causing it?