Reputation: 2143
Can we add and remove the bootstrap typeahead dynamically.
Means in some case I need to give the typeahaed functionality to one textbox and need to remove this functionality for the same input box in another case.
Upvotes: 9
Views: 14086
Reputation: 7150
I had to use a different (and hackier) solution because I'm changing the typeahead data each time I bind it and couldn't get the other answers to work. I'll leave it here in case anyone needs it.
Remove Typeahead
var parent = $('.typeahead').parent();
var html = parent.html();
$('.typeahead).remove();
parent.html(html);
Add Typeahead
$('.typehead').typehead();
Upvotes: 1
Reputation: 19031
I found $('.some-typeahead-parent .tt-dropdown-menu').hide();
to work the best for multiple data set typeahead.
Upvotes: 0
Reputation: 21
This code works for me.
var typeaheadEle = $('#myTypeahead').data('typeahead');
if (typeaheadEle) {typeaheadEle.source = [];}
where myTypeahead is id of the input element.
Upvotes: 1
Reputation: 2300
I know I'm late to the party, below will remove instead of just hide.
$('.typeahead').typeahead('destroy');
Upvotes: 10
Reputation: 2143
I have used the
$('.typeahead').removeClass('dropdown-menu');
and
$('.typeahead').addClass('dropdown-menu');
to hide show that drop-down suggestion.
Upvotes: 2