Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 26e7197

Browse files
committed
Added extra check and onSelectcallback moved to directives.
1 parent beb0b15 commit 26e7197

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

src/uiSelectController.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -433,20 +433,7 @@ uis.controller('uiSelectCtrl',
433433
}
434434
_resetSearchInput();
435435
$scope.$broadcast('uis:select', item);
436-
437-
var locals = {};
438-
locals[ctrl.parserResult.itemName] = item;
439-
440-
$timeout(function(){
441-
if(!ctrl.limitReached)
442-
{
443-
ctrl.onSelectCallback($scope, {
444-
$item: item,
445-
$model: ctrl.parserResult.modelMapper($scope, locals)
446-
});
447-
}
448-
});
449-
436+
450437
if (ctrl.closeOnSelect) {
451438
ctrl.close(skipFocusser);
452439
}

src/uiSelectMultipleDirective.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
175175

176176
scope.$on('uis:select', function (event, item) {
177177
if($select.selected.length >= $select.limit) {
178-
$select.limitReached = true;
179178
return;
180179
}
181-
$select.limitReached = false;
182180
$select.selected.push(item);
181+
var locals = {};
182+
locals[$select.parserResult.itemName] = item;
183+
184+
$timeout(function(){
185+
$select.onSelectCallback(scope, {
186+
$item: item,
187+
$model: $select.parserResult.modelMapper(scope, locals)
188+
});
189+
});
183190
$selectMultiple.updateModel();
184191
});
185192

src/uiSelectSingleDirective.js

+9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp
5151

5252
scope.$on('uis:select', function (event, item) {
5353
$select.selected = item;
54+
var locals = {};
55+
locals[$select.parserResult.itemName] = item;
56+
57+
$timeout(function(){
58+
$select.onSelectCallback(scope, {
59+
$item: item,
60+
$model: $select.parserResult.modelMapper(scope, locals)
61+
});
62+
});
5463
});
5564

5665
scope.$on('uis:close', function (event, skipFocusser) {

test/select.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -2792,6 +2792,23 @@ describe('ui-select tests', function() {
27922792
expect(el.scope().$select.selected.length).toEqual(1);
27932793
});
27942794

2795+
it('should only have 2 items selected and onSelect function should be handeld.',function(){
2796+
scope.onSelectFn = function ($item, $model) {
2797+
scope.$item = $item;
2798+
scope.$model = $model;
2799+
};
2800+
var el = createUiSelectMultiple({onSelect:'onSelectFn($item, $model)'});
2801+
2802+
expect(scope.$item).toBeFalsy();
2803+
expect(scope.$model).toBeFalsy();
2804+
2805+
clickItem(el, 'Samantha');
2806+
$timeout.flush();
2807+
clickItem(el, 'Natasha');
2808+
$timeout.flush();
2809+
expect(el.scope().$select.selected.length).toEqual(2);
2810+
});
2811+
27952812
describe('resetSearchInput option multiple', function () {
27962813
it('should be true by default', function () {
27972814
expect(createUiSelectMultiple().scope().$select.resetSearchInput).toBe(true);

0 commit comments

Comments
 (0)