Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Typeahead only displaying first letter

I'm having a tough time getting Twitter Bootstrap's Typeahead to work. Typeahead is only matching the first letter of an input. My results in the typeahead box looks something like

n
n
n
N
N
n.

My code is

<%= text_field_tag :search, params[:search], "data-provide" => "typeahead", "data-source" => '["USA", "Canada","Mexico"]' %>

Can anyone help?

like image 654
user1634590 Avatar asked Aug 29 '12 23:08

user1634590


1 Answers

Check the combination of quotes that's output in your html for the data-source attribute. I was having the same problem with the following snippet of code.

<input type="text" name="test" id="test" class="span2" data-provide="typeahead" 
data-items="4" data-source="['thisone','another','zzzz']">

changing to the following, which I've seen in other examples, didn't fix it

data-source="["thisone","another","zzzz"]"

but switching to single quotes around the attribute value and double-quotes for the searchable elements fixed it. This works.

data-source='["thisone","another","zzzz"]'
like image 77
Derek Avatar answered Oct 13 '22 12:10

Derek