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

Added open and close event hooks for directive #1153

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
16 changes: 15 additions & 1 deletion src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '';
};
Expand Down Expand Up @@ -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');
});
Expand Down
17 changes: 15 additions & 2 deletions src/uiSelectDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ uis.directive('uiSelect',
if (angular.isDefined(tAttrs.multiple))
tElement.append("<ui-select-multiple/>").removeAttr('multiple');
else
tElement.append("<ui-select-single/>");
tElement.append("<ui-select-single/>");

return function(scope, element, attrs, ctrls, transcludeFn) {

Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
});

};
}
};
Expand Down