简体   繁体   中英

Typeahead.js on Blur Event

I'm using the Twitter Typeahead . There is an issue when I have preloaded data in my text box and on the blur event, the text box is clearing. This is a known issue within the type ahead and it says it was fixed. But I can't quite figure out how to implement the fix.

I have my typeahead initialize like this in the (document).ready function

$('#myTextbox').typeahead({
    name: 'Typeahead',
    valueKey: "Value",
    remote: '/ServiceHandlers/myHandler.ashx?Method=Typeahead&Query=%QUERY',
    template: ['<p>{{Value}}</p>'],
    engine: Hogan
});

The issue says to add something like

$('.typeahead').typeahead('setQuery', '');

But I can't quite see where this would go. Any suggestions on how to fix this issue?

Figured it out!

Just had to set

$('#myTextbox').typeahead('setQuery', $(#myTextbox).val()); 

in the typeahead.open function.

Here was my solution:

var typeaheadElement = $('element-selector');
typeaheadElement.bind('typeahead:open', function() {
  typeaheadElement.typeahead('val', typeaheadElement.val());
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM