diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 486c245a2..7b2e32f67 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -43,7 +43,7 @@ uis.controller('uiSelectCtrl', if (ctrl.searchInput.length !== 1) { throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length); } - + ctrl.isEmpty = function() { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; }; @@ -514,6 +514,20 @@ uis.controller('uiSelectCtrl', } } + $scope.$watch(function(){ + return ctrl.open; + }, function(openState){ + if(openState && ctrl.onOpenCallback){ + ctrl.onOpenCallback($scope, { + $model: ctrl.parserResult.modelMapper($scope, {}) + }); + } else if (!openState && ctrl.onCloseCallback){ + ctrl.onCloseCallback($scope, { + $model: ctrl.parserResult.modelMapper($scope, {}) + }); + } + }); + $scope.$on('$destroy', function() { ctrl.searchInput.off('keyup keydown tagged blur paste'); }); diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 0f537d196..bd01c6024 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -21,7 +21,7 @@ uis.directive('uiSelect', if (angular.isDefined(tAttrs.multiple)) tElement.append("").removeAttr('multiple'); else - tElement.append(""); + tElement.append(""); return function(scope, element, attrs, ctrls, transcludeFn) { @@ -43,7 +43,7 @@ uis.directive('uiSelect', $select.onSelectCallback = $parse(attrs.onSelect); $select.onRemoveCallback = $parse(attrs.onRemove); - + //Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; @@ -293,6 +293,19 @@ uis.directive('uiSelect', element.removeClass(directionUpClassName); } }); + + attrs.$observe('uiSelectOnOpen', function() { + if (attrs.uiSelectOnOpen !== undefined) { + $select.onOpenCallback = $parse(attrs.uiSelectOnOpen); + } + }); + + attrs.$observe('uiSelectOnClose', function() { + if (attrs.uiSelectOnClose !== undefined) { + $select.onCloseCallback = $parse(attrs.uiSelectOnClose); + } + }); + }; } };