From 2b093d7a1f924b3eed76e3730f667f7731703328 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Thu, 4 Jun 2015 16:54:41 -0700 Subject: [PATCH] fix(typeahead): select match on tab for iOS webview - Select match on blur if only it has not been selected upon keydown fix(typeahead): move selected true logic to `select` method --- src/typeahead/typeahead.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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.