Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 56fdbff

Browse files
authored
Broadcast selected items on paste if paste function returns them (#16)
1 parent 139739a commit 56fdbff

File tree

7 files changed

+43
-9
lines changed

7 files changed

+43
-9
lines changed

dist/select.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.8 - 2017-08-15T21:12:35.568Z
4+
* Version: 0.19.8 - 2017-08-16T19:47:39.450Z
55
* License: MIT
66
*/
77

dist/select.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.8 - 2017-08-15T21:12:35.391Z
4+
* Version: 0.19.8 - 2017-08-16T19:47:39.332Z
55
* License: MIT
66
*/
77

@@ -1021,7 +1021,13 @@ uis.controller('uiSelectCtrl',
10211021

10221022
if (data && data.length > 0) {
10231023
if (ctrl.paste) {
1024-
ctrl.paste(data);
1024+
var pastedItems = ctrl.paste(data);
1025+
// broadcast selected items if paste function returns them
1026+
if (pastedItems && pastedItems.length) {
1027+
pastedItems.forEach(function(item) {
1028+
$scope.$broadcast('uis:select', item);
1029+
});
1030+
}
10251031
ctrl.search = EMPTY_SEARCH;
10261032
e.preventDefault();
10271033
e.stopPropagation();

dist/select.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.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/select.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uiSelectController.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,13 @@ uis.controller('uiSelectCtrl',
725725

726726
if (data && data.length > 0) {
727727
if (ctrl.paste) {
728-
ctrl.paste(data);
728+
var pastedItems = ctrl.paste(data);
729+
// broadcast selected items if paste function returns them
730+
if (pastedItems && pastedItems.length) {
731+
pastedItems.forEach(function(item) {
732+
$scope.$broadcast('uis:select', item);
733+
});
734+
}
729735
ctrl.search = EMPTY_SEARCH;
730736
e.preventDefault();
731737
e.stopPropagation();

test/select.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,6 +2894,28 @@ describe('ui-select tests', function () {
28942894
expect(scope.pasteFunc).toHaveBeenCalledWith('tag1');
28952895
});
28962896

2897+
it('should broadcast selected items when paste function returns pasted items', function() {
2898+
scope.pasteFunc = function(str) { return [str] };
2899+
spyOn(scope, '$broadcast');
2900+
2901+
var el = createUiSelectMultiple({tagging: true, paste: "pasteFunc", taggingTokens: ","});
2902+
clickMatch(el);
2903+
triggerPaste(el.find('input'), 'tag1');
2904+
2905+
expect(scope.$broadcast).toHaveBeenCalledWith('uis:select', 'tag1');
2906+
})
2907+
2908+
it('should not broadcast if paste function does not return pasted items', function() {
2909+
scope.pasteFunc = function() {};
2910+
spyOn(scope, '$broadcast');
2911+
2912+
var el = createUiSelectMultiple({tagging: true, paste: "pasteFunc", taggingTokens: ","});
2913+
clickMatch(el);
2914+
triggerPaste(el.find('input'), 'tag1');
2915+
2916+
expect(scope.$broadcast).not.toHaveBeenCalledWith('uis:select', 'tag1');
2917+
})
2918+
28972919
it('should add an id to the search input field', function () {
28982920
var el = createUiSelectMultiple({ inputId: 'inid' });
28992921
var searchEl = $(el).find('input.ui-select-search');

0 commit comments

Comments
 (0)