Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I wanted to achieve a similar thing, so I took a look at the typeahead code and hacked something together, see the below:</p> <p>Its still is a bit buggy with handling placeholders and closing the dropdown when you click away, but this gives me a toggle button that I can click that is a sibling to my input element, and it fetches the full list from the dataset instead of a small suggestion list.</p> <p>Example html (I am using custom typeahead data-bindings for knockout, but you get the idea):</p> <pre><code> &lt;div class="col-md-12 input-group tt-dropdown-group"&gt; &lt;input id="category" name="category" type="text" class="form-control" data-bind=" attr: { placeholder: categoryCaption }, typeahead: categories, typeaheadValueKey: 'Name', typeaheadValue: category, typeaheadDestroy: true" /&gt; &lt;span id="category-drop" class="input-group-addon tt-dropdown-icon"&gt; &lt;span class="glyphicon glyphicon-chevron-down"&gt;&lt;/span&gt; &lt;/span&gt; &lt;/div&gt; </code></pre> <p>Example javascript using jQuery:</p> <pre><code> $(".tt-dropdown-group .tt-dropdown-icon").on("click", function() { var $input = $(this).parent(".tt-dropdown-group").find("input.tt-query"); var $toggleBtn = $(this); // these are all expected to be objects so falsey check is fine if (!$input.data() || !$input.data().ttView || !$input.data().ttView.datasets || !$input.data().ttView.dropdownView || !$input.data().ttView.inputView) { return; } var ttView = $input.data().ttView; var toggleAttribute = $toggleBtn.attr("data-toggled"); if (!toggleAttribute || toggleAttribute === "off") { $toggleBtn.attr("data-toggled", "on"); $input.typeahead("setQuery", ""); if ($.isArray(ttView.datasets) &amp;&amp; ttView.datasets.length &gt; 0) { // only pulling the first dataset for this hack var fullSuggestionList = []; // renderSuggestions expects an suggestions array not an object $.each(ttView.datasets[0].itemHash, function(i, item) { fullSuggestionList.push(item); }); ttView.dropdownView.renderSuggestions(ttView.datasets[0], fullSuggestionList); ttView.inputView.setHintValue(""); ttView.dropdownView.open(); } } else if (toggleAttribute === "on") { $toggleBtn.attr("data-toggled", "off"); ttView.dropdownView.close(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload