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

Added "on-shown" attribute #1526

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ uis.controller('uiSelectCtrl',

$scope.$broadcast('uis:activate');

$timeout(function(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to do a $timeout?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I don't remember, but I guess it was added to be sure it's triggered after the main cycle.

ctrl.onShowCallback($scope);
});

ctrl.open = true;

ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
Expand Down
1 change: 1 addition & 0 deletions src/uiSelectDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ uis.directive('uiSelect',

$select.onSelectCallback = $parse(attrs.onSelect);
$select.onRemoveCallback = $parse(attrs.onRemove);
$select.onShowCallback = $parse(attrs.onShow);

//Limit the number of selections allowed
$select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined;
Expand Down
22 changes: 22 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,28 @@ describe('ui-select tests', function() {

});

it('should invoke show callback on activate', function () {
scope.onShowFn = function (someArg) {
scope.someArg = someArg;
};
var el = compileTemplate(
'<ui-select on-show="onShowFn(\'shown\')" ng-model="selection.selected"> \
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
<ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
<div ng-bind-html="person.name | highlight: $select.search"></div> \
<div ng-bind-html="person.email | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select>'
);

expect(scope.someArg).toBeFalsy();
clickMatch(el);
$timeout.flush();

expect(scope.someArg).toEqual('shown');
});


it('should set $item & $model correctly when invoking callback on select and no single prop. binding', function () {

scope.onSelectFn = function ($item, $model, $label) {
Expand Down