Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
112
rated 0 times [  114] [ 2]  / answers: 1 / hits: 20651  / 12 Years ago, sun, june 3, 2012, 12:00:00

I'm working on a search functionality for my website and I'm using Bootstrap's typeahead to show the results. So far so good. But what I want is to extend the function so that I could add an image and some other item, say description, etc. According to this post, that is possible: custom typeahead.



Basically I need something like this as each result item:



<div class=resultContainer>
<div class=resultImage><img /></div>
<div class=resultDesc></div>
<div class=resultLabel></div>
</div>


Now it's:



<li><a href=#></a></li>


And this doesn't even work with a longer text than the width of the typeahead. So the text doesn't go to the next line and hence doesn't fit the <li>. How can I use the the custom layout I want? (btw I have an array of arrays of results. Each sub-array contains img, desc, etc.). This is what I have right now:
enter



Thanks in advance.


More From » html

 Answers
138

Use the highlighter method:



$('.typeahead').typeahead({
highlighter: function(item){
return <div>.......</div>;
}
});



Method used to highlight autocomplete results. Accepts a single
argument item and has the scope of the typeahead instance. Should
return html.



[#85175] Friday, June 1, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
benitoh

Total Points: 150
Total Questions: 113
Total Answers: 104

Location: India
Member since Wed, Aug 26, 2020
4 Years ago
benitoh questions
Sun, Mar 21, 21, 00:00, 3 Years ago
Mon, May 13, 19, 00:00, 5 Years ago
;