Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter's Typeahead - Debug Rendered HTML?

I'm having problems debugging Twitter's Typeahead script. For some reason the following header displays fine...

header: '<h3 class="tt-title">Ads</h3>',

But when I swap out the H3 for divs as follows...

header: '<div class="tt-title">Ads</div>',

I get blank spaces. I know something is rendering, but the text is now showing up. I have a feeling it is a CSS issue, but I can't view the rendered HTML of the drop down in developer tools. The drop down closes automatically before I have a chance to navigate to it in the source.

Anyone know how to prevent it from closing once opened? I'm using Chrome's developer tools.

like image 312
Adam Youngers Avatar asked Mar 21 '14 17:03

Adam Youngers


People also ask

What is twitter typeahead js?

Twitter typeahead. js is a fast and battle-tested jQuery plugin for auto completion. Today we're open sourcing the code on GitHub under the MIT license. By sharing a piece of our infrastructure with the open source community, we hope to evolve typeahead. js further with community input.

What is typeahead bootstrap?

Typeahead. A basic, easily extended plugin for quickly creating elegant typeaheads with any form text input.

What is typeahead jQuery?

jQuery plugin that provides Typeahead (autocomplete) Search preview from Json object(s) via same domain Ajax request or cross domain Jsonp and offers data compression inside Local Storage. The plugin is built with a lot of options and callbacks to allow customization.

How do you make a typeahead?

To create Twitter typeaheads first download typeahead. js from their official page — https://twitter.github.io/typeahead.js/ and include in your project, after that you can turn any text-based <input> element into a typeahead. Twitter typeaheads require jQuery 1.9+ to work.


2 Answers

If you are using chrome developer tools you can simply right click on the element class="tt-dataset-0" in your elements tab and choose break on.../subtree modification. If you start typing in the typeahead input field the debugger will break. Now you can right click on the element you wish to inspect.

like image 52
marco_ Avatar answered Oct 19 '22 17:10

marco_


I've never used Typeahead before, but I checked their docs and their demo-page. And it sure was kind of tricky.

Anyhow, got it to work with this simple script that you can paste in your browser console, which forces you Typeahead searchbox to open, and stay open while you poke around in the element inspector:

$('.typeahead').focus().typeahead('val', '').focus().typeahead('val', 'what ever value you want to test');

At least in chrome, the suggestion box even stays open on right click > inspect element.

Update; the OP asked for an more extensive explanation:

The code above is jQuery and takes a selector – the element that contains the Typeahead. A screenshot:

enter image description here

The selector in this example is specific for the demo-pages for the Typeahead library. You might need to tweak it depending on how you initialize your own Typeahead.

like image 38
Marcus Olsson Avatar answered Oct 19 '22 19:10

Marcus Olsson