From ab93cc117cb4cc51767e20dfb7322107891def46 Mon Sep 17 00:00:00 2001 From: Maxim Syabro Date: Mon, 20 Jun 2016 13:59:14 +0600 Subject: [PATCH] Added "on-shown" attribute --- src/uiSelectController.js | 4 ++++ src/uiSelectDirective.js | 1 + test/select.spec.js | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index ba3e6d56d..fbacbf7d6 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -112,6 +112,10 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:activate'); + $timeout(function(){ + ctrl.onShowCallback($scope); + }); + ctrl.open = true; ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 9fdeb3e66..91061eccf 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -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; diff --git a/test/select.spec.js b/test/select.spec.js index 063b9fb66..66d682629 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -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( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + + 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) {