jquery - typeahead.js default select the first suggestion -


I am using the angularJS library by type siftion for typeahead, which in fact typed head. JS and bleeding Uses JS and Jazzery. I have typeheadhead.js v 0.10.2 and jquery 1.10.2. My goal is to create a facility for search where users can only select from the suggestions, so I have implemented it in such a way that if the result of the suggestion is not selected Then a query has been submitted with the tap parameter and the suggestion has been submitted. I have set my options as

  minLength: 1, hightlight: true, editable: false   

I have three datasets:

  var lahounders = new bloodhound ({Datum tokoniser: bluehound.tokenizers.obj.whitespace ('name'), querytokenizer: bloodhound.tokenizers.whitespace, prefetch: {url: '/ url / param' , Filter: function (store) {return $ .map (store, function (store) {return {name: store.name}}}}}});   

I call clear cash for all of them and then initialize them, just to let you know. I am not very expert in this, but doing so solves my purpose

  bloodhoundStores.clearPrefetchCache (); (On all three datasets) bloodhoundStores.initialize ();   

Then I have set the suggestion to present such as:

  {Name: 'Locality', performance: ' Name ', Source: BloodhoundLocality.adapter (), Template: {Header:' & lt; H4 style = "padding-down: 2px;" & Gt; & Lt; I class = "fa-pA-location-arrow" & gt; & Lt; / I & gt; Locality & lieutenant; / H4> ', Empty: [' & lt; P & gt; ',' & Lt; Span & gt; No results found & lt; / Span & gt; ',' & Lt; / P & gt; ']. ('\ N'), Suggestions: Handlebars .compile ('& lt; p & gt; & lt; span class = "sentence-case" & gt; {{name}}  & lt; / P & gt; ')}}   

My problem is that if the user types in a search term, then I want to first suggestion, if any, to select. I decided to resolve the issues with Twitter TypeEhead Have seen for solutions in the JS Gitb repository. I am unable to find a way to work them for me. Please help me or suggest me a different way to implement it.

Thanks in advance

Here's my solution:

I have a closer that types all my search form arguments, including the TypeHead source (and related). It seems that there is something like this:

  (function () {var $ search box, search, first match, search result handler, typidylbackback, typeahhead source; typeahhead source = function (query, CB) {TypeaheadCallback = cb; doSearch (query);}; doSearch = function (term) {// Here are some stuff to query. // When results come back, turn off the call for search. Resolverhandler.} ; SearchResultHandler = function (feedback) {var data = JSON .parse (response.body); // I have previously used sock.js in my app If the match = data [0] .termToFillInSearchBox; if (typeahhead callback) {typeahead callback (data);}}; $ searchBox.on ("typeahead: off", function (evt) {// search against some expected pattern What is the match in the field. In my case, I am looking for "some value .1234". If I do not match the input, and I have something in the "first match", and then // Option option. If (! / \ W + \. \ D + /. Test ($ searchBox.val ()) & amp; First Match! == Undefined) {$ searchbox Well (First Match); First Match = Undefined ;}});} ());    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -