Option showHintOnFocus: "all" doesn't work anymore after selecting an item
Opened this issue · 2 comments
aureole82 commented
Given the following snippet:
var source = ["Coffee", "Tea", "Cereales", "Toast", "Butter", "Eggs", "Beacon", "Fruits"];
var $input = $("#breakfast");
$input.typeahead({
minLength: 0,
showHintOnFocus: "all",
source: source
});
- Click into
#breakfast
input (all hints will be display). - Select one hint (
#breakfast
input got focus again). - Click somewhere else and click into
#breakfast
input again.
No hints are displayed!
Try: https://jsfiddle.net/2dw5e6aj/
I assume the blur
function doesn't set this.focused = false;
properly. So the focus
function won't fire this.lookup("");
?!
thorsten commented
I can confirm the issue.
joshward commented
I dug into a workaround for this issue for our project.
As OP suggested the issue is that focus
only fires this.lookup("")
when !this.focused
.
Bootstrap-3-Typeahead/bootstrap3-typeahead.js
Lines 609 to 618 in fc2d5dc
Selecting doesn't automatically blur the input and even on blur the handler fails to set
this.focused
because it's gated behind this.shown
which is false because the suggestions are already closed. Bootstrap-3-Typeahead/bootstrap3-typeahead.js
Lines 626 to 632 in fc2d5dc
my workaround was to manually force a blur and set the this.focused
to false
e.g.
afterSelect: value => {
// what ever other handling code
setTimeout(() => {
$(input).blur();
$(input).data('typeahead').focused = false;
};
}