diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 1fe28401ab..050b58dccd 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -71,6 +71,11 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap var hasFocus; + //Used to avoid bug in iOS webview where iOS keyboard does not fire + //mousedown & mouseup events + //Issue #3699 + var selected; + //create a child scope for the typeahead directive so we are not polluting original scope //with typeahead-specific data (matches, query etc.) var scope = originalScope.$new(); @@ -255,6 +260,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap var locals = {}; var model, item; + selected = true; locals[parserResult.itemName] = item = scope.matches[activeIdx].model; model = parserResult.modelMapper(originalScope, locals); $setModelValue(originalScope, model); @@ -283,7 +289,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap } // if there's nothing selected (i.e. focusFirst) and enter is hit, don't do anything - if (scope.activeIdx == -1 && (evt.which === 13 || evt.which === 9)) { + if (scope.activeIdx === -1 && (evt.which === 13 || evt.which === 9)) { return; } @@ -311,7 +317,14 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap }); element.bind('blur', function (evt) { + if (scope.matches.length && scope.activeIdx !== -1 && !selected) { + selected = true; + scope.$apply(function() { + scope.select(scope.activeIdx); + }); + } hasFocus = false; + selected = false; }); // Keep reference to click handler to unbind it.