Skip to content

Commit 4640d21

Browse files
author
Alex Bughiu
committed
fix: Added typeahead-prepend and typeahead-append options
1 parent d62d9b7 commit 4640d21

File tree

5 files changed

+143
-35
lines changed

5 files changed

+143
-35
lines changed

dist/ui-bootstrap-tpls.js

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* angular-ui-bootstrap
33
* http://angular-ui.github.io/bootstrap/
44
5-
* Version: 2.5.4 - 2020-04-24
5+
* Version: 2.5.4 - 2020-05-28
66
* License: MIT
77
*/angular.module("ui.bootstrap", ["ui.bootstrap.tpls", "ui.bootstrap.collapse","ui.bootstrap.tabindex","ui.bootstrap.accordion","ui.bootstrap.alert","ui.bootstrap.buttons","ui.bootstrap.carousel","ui.bootstrap.dateparser","ui.bootstrap.isClass","ui.bootstrap.datepicker","ui.bootstrap.position","ui.bootstrap.datepickerPopup","ui.bootstrap.debounce","ui.bootstrap.multiMap","ui.bootstrap.dropdown","ui.bootstrap.stackedMap","ui.bootstrap.modal","ui.bootstrap.paging","ui.bootstrap.pager","ui.bootstrap.pagination","ui.bootstrap.tooltip","ui.bootstrap.popover","ui.bootstrap.progressbar","ui.bootstrap.rating","ui.bootstrap.tabs","ui.bootstrap.timepicker","ui.bootstrap.typeahead"]);
88
angular.module("ui.bootstrap.tpls", ["uib/template/accordion/accordion-group.html","uib/template/accordion/accordion.html","uib/template/alert/alert.html","uib/template/carousel/carousel.html","uib/template/carousel/slide.html","uib/template/datepicker/datepicker.html","uib/template/datepicker/day.html","uib/template/datepicker/month.html","uib/template/datepicker/year.html","uib/template/datepickerPopup/popup.html","uib/template/modal/window.html","uib/template/pager/pager.html","uib/template/pagination/pagination.html","uib/template/tooltip/tooltip-html-popup.html","uib/template/tooltip/tooltip-popup.html","uib/template/tooltip/tooltip-template-popup.html","uib/template/popover/popover-html.html","uib/template/popover/popover-template.html","uib/template/popover/popover.html","uib/template/progressbar/bar.html","uib/template/progressbar/progress.html","uib/template/progressbar/progressbar.html","uib/template/rating/rating.html","uib/template/tabs/tab.html","uib/template/tabs/tabset.html","uib/template/timepicker/timepicker.html","uib/template/typeahead/typeahead-match.html","uib/template/typeahead/typeahead-popup.html"]);
@@ -6792,6 +6792,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
67926792
//a callback executed when a match is selected
67936793
var onSelectCallback = $parse(attrs.typeaheadOnSelect);
67946794

6795+
var valueFromLabel = attrs.typeaheadValueFromLabel;
6796+
67956797
//should it select highlighted popup value when losing focus?
67966798
var isSelectOnBlur = angular.isDefined(attrs.typeaheadSelectOnBlur) ? originalScope.$eval(attrs.typeaheadSelectOnBlur) : false;
67976799

@@ -6831,6 +6833,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
68316833

68326834
//expressions used by typeahead
68336835
var parserResult = typeaheadParser.parse(attrs.uibTypeahead);
6836+
var typeaheadPrepend = originalScope.$eval(attrs.typeaheadPrepend);
6837+
var typeaheadAppend = originalScope.$eval(attrs.typeaheadAppend);
68346838

68356839
var hasFocus;
68366840

@@ -6955,19 +6959,45 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
69556959
//but we are interested only in responses that correspond to the current view value
69566960
var onCurrentRequest = inputValue === modelCtrl.$viewValue;
69576961
if (onCurrentRequest && hasFocus) {
6958-
if (matches && matches.length > 0) {
6962+
if (matches && matches.length > 0 || typeaheadPrepend || typeaheadAppend) {
69596963
scope.activeIdx = focusFirst ? 0 : -1;
69606964
isNoResultsSetter(originalScope, false);
69616965
scope.matches.length = 0;
69626966

69636967
//transform labels
6964-
for (var i = 0; i < matches.length; i++) {
6965-
locals[parserResult.itemName] = matches[i];
6966-
scope.matches.push({
6967-
id: getMatchId(i),
6968-
label: parserResult.viewMapper(scope, locals),
6969-
model: matches[i]
6970-
});
6968+
if (matches) {
6969+
for (var i = 0; i < matches.length; i++) {
6970+
locals[parserResult.itemName] = matches[i];
6971+
scope.matches.push({
6972+
id: getMatchId(i),
6973+
label: parserResult.viewMapper(scope, locals),
6974+
model: matches[i]
6975+
});
6976+
}
6977+
}
6978+
6979+
if (typeaheadPrepend) {
6980+
for (var j=0; j<typeaheadPrepend.length; j++) {
6981+
var item = typeaheadPrepend[j];
6982+
var index = i + j;
6983+
scope.matches.splice(j,0,{
6984+
id: getMatchId(index),
6985+
label: item.name,
6986+
model: item
6987+
});
6988+
}
6989+
}
6990+
6991+
if (typeaheadAppend) {
6992+
for (var k=0; k<typeaheadAppend.length; k++) {
6993+
var item = typeaheadAppend[k];
6994+
var index = i + (j || 0) + k;
6995+
scope.matches.splice(index,0,{
6996+
id: getMatchId(index),
6997+
label: item.name,
6998+
model: item
6999+
});
7000+
}
69717001
}
69727002

69737003
scope.query = inputValue;
@@ -7086,13 +7116,19 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
70867116
modelCtrl.$setValidity('editable', true);
70877117
modelCtrl.$setValidity('parse', true);
70887118

7119+
var label = parserResult.viewMapper(originalScope, locals);
7120+
70897121
onSelectCallback(originalScope, {
70907122
$item: item,
70917123
$model: model,
7092-
$label: parserResult.viewMapper(originalScope, locals),
7124+
$label: label,
70937125
$event: evt
70947126
});
70957127

7128+
if (valueFromLabel === 'true') {
7129+
$timeout(function() { element.val(label); });
7130+
}
7131+
70967132
resetMatches();
70977133

70987134
//return focus to the input element if a match was selected via a mouse click event

dist/ui-bootstrap-tpls.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui-bootstrap.js

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* angular-ui-bootstrap
33
* http://angular-ui.github.io/bootstrap/
44
5-
* Version: 2.5.4 - 2020-04-24
5+
* Version: 2.5.4 - 2020-05-28
66
* License: MIT
77
*/angular.module("ui.bootstrap", ["ui.bootstrap.collapse","ui.bootstrap.tabindex","ui.bootstrap.accordion","ui.bootstrap.alert","ui.bootstrap.buttons","ui.bootstrap.carousel","ui.bootstrap.dateparser","ui.bootstrap.isClass","ui.bootstrap.datepicker","ui.bootstrap.position","ui.bootstrap.datepickerPopup","ui.bootstrap.debounce","ui.bootstrap.multiMap","ui.bootstrap.dropdown","ui.bootstrap.stackedMap","ui.bootstrap.modal","ui.bootstrap.paging","ui.bootstrap.pager","ui.bootstrap.pagination","ui.bootstrap.tooltip","ui.bootstrap.popover","ui.bootstrap.progressbar","ui.bootstrap.rating","ui.bootstrap.tabs","ui.bootstrap.timepicker","ui.bootstrap.typeahead"]);
88
angular.module('ui.bootstrap.collapse', [])
@@ -6791,6 +6791,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
67916791
//a callback executed when a match is selected
67926792
var onSelectCallback = $parse(attrs.typeaheadOnSelect);
67936793

6794+
var valueFromLabel = attrs.typeaheadValueFromLabel;
6795+
67946796
//should it select highlighted popup value when losing focus?
67956797
var isSelectOnBlur = angular.isDefined(attrs.typeaheadSelectOnBlur) ? originalScope.$eval(attrs.typeaheadSelectOnBlur) : false;
67966798

@@ -6830,6 +6832,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
68306832

68316833
//expressions used by typeahead
68326834
var parserResult = typeaheadParser.parse(attrs.uibTypeahead);
6835+
var typeaheadPrepend = originalScope.$eval(attrs.typeaheadPrepend);
6836+
var typeaheadAppend = originalScope.$eval(attrs.typeaheadAppend);
68336837

68346838
var hasFocus;
68356839

@@ -6954,19 +6958,45 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
69546958
//but we are interested only in responses that correspond to the current view value
69556959
var onCurrentRequest = inputValue === modelCtrl.$viewValue;
69566960
if (onCurrentRequest && hasFocus) {
6957-
if (matches && matches.length > 0) {
6961+
if (matches && matches.length > 0 || typeaheadPrepend || typeaheadAppend) {
69586962
scope.activeIdx = focusFirst ? 0 : -1;
69596963
isNoResultsSetter(originalScope, false);
69606964
scope.matches.length = 0;
69616965

69626966
//transform labels
6963-
for (var i = 0; i < matches.length; i++) {
6964-
locals[parserResult.itemName] = matches[i];
6965-
scope.matches.push({
6966-
id: getMatchId(i),
6967-
label: parserResult.viewMapper(scope, locals),
6968-
model: matches[i]
6969-
});
6967+
if (matches) {
6968+
for (var i = 0; i < matches.length; i++) {
6969+
locals[parserResult.itemName] = matches[i];
6970+
scope.matches.push({
6971+
id: getMatchId(i),
6972+
label: parserResult.viewMapper(scope, locals),
6973+
model: matches[i]
6974+
});
6975+
}
6976+
}
6977+
6978+
if (typeaheadPrepend) {
6979+
for (var j=0; j<typeaheadPrepend.length; j++) {
6980+
var item = typeaheadPrepend[j];
6981+
var index = i + j;
6982+
scope.matches.splice(j,0,{
6983+
id: getMatchId(index),
6984+
label: item.name,
6985+
model: item
6986+
});
6987+
}
6988+
}
6989+
6990+
if (typeaheadAppend) {
6991+
for (var k=0; k<typeaheadAppend.length; k++) {
6992+
var item = typeaheadAppend[k];
6993+
var index = i + (j || 0) + k;
6994+
scope.matches.splice(index,0,{
6995+
id: getMatchId(index),
6996+
label: item.name,
6997+
model: item
6998+
});
6999+
}
69707000
}
69717001

69727002
scope.query = inputValue;
@@ -7085,13 +7115,19 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
70857115
modelCtrl.$setValidity('editable', true);
70867116
modelCtrl.$setValidity('parse', true);
70877117

7118+
var label = parserResult.viewMapper(originalScope, locals);
7119+
70887120
onSelectCallback(originalScope, {
70897121
$item: item,
70907122
$model: model,
7091-
$label: parserResult.viewMapper(originalScope, locals),
7123+
$label: label,
70927124
$event: evt
70937125
});
70947126

7127+
if (valueFromLabel === 'true') {
7128+
$timeout(function() { element.val(label); });
7129+
}
7130+
70957131
resetMatches();
70967132

70977133
//return focus to the input element if a match was selected via a mouse click event

dist/ui-bootstrap.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/typeahead/typeahead.js

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
6464
//a callback executed when a match is selected
6565
var onSelectCallback = $parse(attrs.typeaheadOnSelect);
6666

67+
var valueFromLabel = attrs.typeaheadValueFromLabel;
68+
6769
//should it select highlighted popup value when losing focus?
6870
var isSelectOnBlur = angular.isDefined(attrs.typeaheadSelectOnBlur) ? originalScope.$eval(attrs.typeaheadSelectOnBlur) : false;
6971

@@ -103,6 +105,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
103105

104106
//expressions used by typeahead
105107
var parserResult = typeaheadParser.parse(attrs.uibTypeahead);
108+
var typeaheadPrepend = originalScope.$eval(attrs.typeaheadPrepend);
109+
var typeaheadAppend = originalScope.$eval(attrs.typeaheadAppend);
106110

107111
var hasFocus;
108112

@@ -227,19 +231,45 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
227231
//but we are interested only in responses that correspond to the current view value
228232
var onCurrentRequest = inputValue === modelCtrl.$viewValue;
229233
if (onCurrentRequest && hasFocus) {
230-
if (matches && matches.length > 0) {
234+
if (matches && matches.length > 0 || typeaheadPrepend || typeaheadAppend) {
231235
scope.activeIdx = focusFirst ? 0 : -1;
232236
isNoResultsSetter(originalScope, false);
233237
scope.matches.length = 0;
234238

235239
//transform labels
236-
for (var i = 0; i < matches.length; i++) {
237-
locals[parserResult.itemName] = matches[i];
238-
scope.matches.push({
239-
id: getMatchId(i),
240-
label: parserResult.viewMapper(scope, locals),
241-
model: matches[i]
242-
});
240+
if (matches) {
241+
for (var i = 0; i < matches.length; i++) {
242+
locals[parserResult.itemName] = matches[i];
243+
scope.matches.push({
244+
id: getMatchId(i),
245+
label: parserResult.viewMapper(scope, locals),
246+
model: matches[i]
247+
});
248+
}
249+
}
250+
251+
if (typeaheadPrepend) {
252+
for (var j=0; j<typeaheadPrepend.length; j++) {
253+
var item = typeaheadPrepend[j];
254+
var index = i + j;
255+
scope.matches.splice(j,0,{
256+
id: getMatchId(index),
257+
label: item.name,
258+
model: item
259+
});
260+
}
261+
}
262+
263+
if (typeaheadAppend) {
264+
for (var k=0; k<typeaheadAppend.length; k++) {
265+
var item = typeaheadAppend[k];
266+
var index = i + (j || 0) + k;
267+
scope.matches.splice(index,0,{
268+
id: getMatchId(index),
269+
label: item.name,
270+
model: item
271+
});
272+
}
243273
}
244274

245275
scope.query = inputValue;
@@ -358,13 +388,19 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
358388
modelCtrl.$setValidity('editable', true);
359389
modelCtrl.$setValidity('parse', true);
360390

391+
var label = parserResult.viewMapper(originalScope, locals);
392+
361393
onSelectCallback(originalScope, {
362394
$item: item,
363395
$model: model,
364-
$label: parserResult.viewMapper(originalScope, locals),
396+
$label: label,
365397
$event: evt
366398
});
367399

400+
if (valueFromLabel === 'true') {
401+
$timeout(function() { element.val(label); });
402+
}
403+
368404
resetMatches();
369405

370406
//return focus to the input element if a match was selected via a mouse click event

0 commit comments

Comments
 (0)