From 2499ed94d027b4373d1f97ed9648f14344c453ba Mon Sep 17 00:00:00 2001 From: Rinku Kazeno Date: Sun, 7 Feb 2016 02:49:22 +0000 Subject: [PATCH 1/3] Added reopen-on-click attribute (Issue #759) Added code to allow to reopen the typeahead list on click, as per issue #759. This requires adding the "typeahead-reopen-on-click" boolean attribute to the typeahead input, example: Only works on typeahead-editable="true" since otherwise the view value is erased on blur. --- src/typeahead/typeahead.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 6cf678b40a..599a44302e 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -81,6 +81,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap var showHint = originalScope.$eval(attrs.typeaheadShowHint) || false; + var reopenOnClick = originalScope.$eval(attrs.typeaheadReopenOnClick) || false; + //INTERNAL VARIABLES //model setter executed upon match selection @@ -451,6 +453,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap if (!$rootScope.$$phase) { scope.$digest(); } + } else if (reopenOnClick && element[0] === evt.target && element.val().length) { + element.focus(); + hasFocus = true; + getMatchesAsync(modelCtrl.$viewValue, evt); } }; From c049b238665d820d14518c4aaccd55659ac10218 Mon Sep 17 00:00:00 2001 From: Rinku Kazeno Date: Sun, 7 Feb 2016 02:53:50 +0000 Subject: [PATCH 2/3] use $viewValue instead of element.val() --- src/typeahead/typeahead.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 599a44302e..c75b018078 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -453,7 +453,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap if (!$rootScope.$$phase) { scope.$digest(); } - } else if (reopenOnClick && element[0] === evt.target && element.val().length) { + } else if (reopenOnClick && element[0] === evt.target && modelCtrl.$viewValue.length) { element.focus(); hasFocus = true; getMatchesAsync(modelCtrl.$viewValue, evt); From 2ec051e3fea3a6c567a6084302aeff822403f858 Mon Sep 17 00:00:00 2001 From: Rinku Kazeno Date: Sun, 7 Feb 2016 03:11:43 +0000 Subject: [PATCH 3/3] check if modelCtrl.$viewValue is set prevent modelCtrl.$viewValue.length from returning an error if modelCtrl.$viewValue is undefined --- src/typeahead/typeahead.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index c75b018078..625498d30b 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -453,7 +453,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap if (!$rootScope.$$phase) { scope.$digest(); } - } else if (reopenOnClick && element[0] === evt.target && modelCtrl.$viewValue.length) { + } else if (reopenOnClick && element[0] === evt.target && modelCtrl.$viewValue && modelCtrl.$viewValue.length) { element.focus(); hasFocus = true; getMatchesAsync(modelCtrl.$viewValue, evt);