typeahead-on-select is not being fired when selecting a item with the mouse and batarang is enabled
typeahead-on-select is not being fired when selecting an item with the mouse. Tested with angular-bootstrap 0.12.0 and angular 1.3.6
A possible fix could be the following: adding the code that is being executed when an item is selected using the keyboard.
// Keep reference to click handler to unbind it.
var dismissClickHandler = function (evt) {
if (element[0] !== evt.target) {
// Proposed patch: select the clicked item
scope.$apply(function () {
scope.select(scope.activeIdx);
});
resetMatches();
scope.$digest();
}
};
I have the same problem and this seems to work great. But I haven't looked through the code enough to know if this is the best place to put it.
I encountered the same problem with angular-bootstrap 0.12.0 and angular 1.2.9. kdekooter's fix works for me, but I altered it with the following minor change due to an error happening when deselecting the menu without making any selections
// Proposed patch: select the clicked item
scope.$apply(function () {
if (scope.activeIdx != -1) {
scope.select(scope.activeIdx);
}
});
Can we get an estimate on when this will be fixed? It's a show-stopper for the typeahead directive.
I'm not sure where to apply kdekooter/thardy's fix
my attribute on the text input is : typeahead-on-select="onSelect($item,$model,$label)" my controller has function : $scope.onSelect = function ($item, $model, $label) { console.log($item); };
where should i paste the fix to - the controller ? or inside the onSelect function.
EDIT : ok i get it ! Its a fix for typeahead.js
@andy4545 glad you found it. Maybe you can submit a PR?
not 100% fix yet...
will submit PR when i get a proper look at it later
Just to be clear, this "fix" is not ideal. It's just a hack. If the user clicks elsewhere on the screen (usually with the intent to take no action), whatever item was highlighted will be selected.
What we need is for a real fix to be put in place. A fix that allows a mouse click to select an item in an angular-ui typeahead. We need typeahead to work the way it was intended.
To reiterate the versions, mouse clicks aren't selecting an item using ui-bootstrap 0.12.0 and Angular 1.2.27 and 1.2.28. This isn't just an issue with angular 1.3.x.
In trying to distill this down into a simple demo to display the problem, my problem with the above versions went away. We are using a nasty combo of jquery mobile plus angular, so I'm not at all surprised. That's the value in trying to distill the problem. Angular 1.2.27 and ui-bootstrap 0.12.0 do not appear to have this problem.
Working for me now with angular 1.3.8, angular-bootstrap 0.12.0 and jquery 2.1.3. Thanks @thardy!
Updated my versions last week and just noticed the same combo of versions is also not working for me (angular 1.3.8, ui 0.12, jquery 2.1.3). I'm using the all-in-one ui-bootstrap.tpls.js version.
Selecting by keyboard with enter key does correctly fire typeahead-on-select callback.
Was working previously on angular 1.3.4, ui 0.12, jquery 2.1.1.
Using patch from @thardy to get it working.
Excuse me, what version combination does not have this problem?
I'm experiencing this as well. angular v1.2.28, angular-bootstrap v.0.12.0
Same here, angular 1.3.0, angular-bootstrap 0.10
Same problem, the mouse click doesn't do anything, using Angular 1.3.2 and Angular-Bootstrap 0.11.2
So this isn't perfect but at least it maintains what I believe is supposed to be the default behavior of the typeahead. Beyond what @thardy proposed I only wanted the item to be selected if the user clicks an item in the actual typeahead list:
// Proposed patch: select the clicked item(only if clicking on the typeahead dropdown)
if(evt.target.parentElement.id.indexOf("typeahead") != -1) {
scope.$apply(function () {
if (scope.activeIdx != -1) {
scope.select(scope.activeIdx);
}
});
}
There is probably a better way to detect this but this is just my quick and dirty proposal.
@rbj325 : is this something for people to put into their own code, or is this a change in the library?
@danielbsig This is a change to the library, in the typeahead module. The above code goes into the dismissClickHandler function.
I'm experiencing issue with angular 1.2.23 and angular-bootstrap v.0.12
I am not able to reproduce this here with the current master - in fact, it appears to be working.
There is a possibility that this was fixed. Closing this as it seems invalid currently.
If someone is able to reproduce this based on current master, then post it here and I will reopen the ticket & investigate further.