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

feat(uiSelectMultiple): adds 'onMatchSelect' callback option #2173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/bootstrap/match-multiple.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tabindex="-1"
type="button"
ng-disabled="$select.disabled"
ng-click="$selectMultiple.activeMatchIndex = $index;"
ng-click="$selectMultiple.selectMatch($index);"
ng-class="{'btn-primary':$selectMultiple.activeMatchIndex === $index, 'select-locked':$select.isLocked(this, $index)}"
ui-select-sort="$select.selected">
<span class="close ui-select-match-close" ng-hide="$select.disabled" ng-click="$selectMultiple.removeChoice($index)">&nbsp;&times;</span>
Expand Down
1 change: 1 addition & 0 deletions src/select2/match-multiple.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-->
<span class="ui-select-match">
<li class="ui-select-match-item select2-search-choice" ng-repeat="$item in $select.selected track by $index"
ng-click="$selectMultiple.selectMatch($index);"
ng-class="{'select2-search-choice-focus':$selectMultiple.activeMatchIndex === $index, 'select2-locked':$select.isLocked(this, $index)}"
ui-select-sort="$select.selected">
<span uis-transclude-append></span>
Expand Down
4 changes: 2 additions & 2 deletions src/selectize/match-multiple.tpl.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="ui-select-match" data-value
ng-repeat="$item in $select.selected track by $index"
ng-click="$selectMultiple.activeMatchIndex = $index;"
ng-click="$selectMultiple.selectMatch($index);"
ng-class="{'active':$selectMultiple.activeMatchIndex === $index}"
ui-select-sort="$select.selected">
<span class="ui-select-match-item"
ng-class="{'select-locked':$select.isLocked(this, $index)}">
<span uis-transclude-append></span>
<span class="remove ui-select-match-close" ng-hide="$select.disabled" ng-click="$selectMultiple.removeChoice($index)">&times;</span>
</span>
</div>
</div>
5 changes: 3 additions & 2 deletions src/uiSelectMatchDirective.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) {
uis.directive('uiSelectMatch', ['uiSelectConfig', '$parse', function(uiSelectConfig, $parse) {
return {
restrict: 'EA',
require: '^uiSelect',
Expand All @@ -13,7 +13,7 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) {
var theme = getAttribute(parent, 'theme') || uiSelectConfig.theme;
var multi = angular.isDefined(getAttribute(parent, 'multiple'));

return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html');
return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html');
},
link: function(scope, element, attrs, $select) {
$select.lockChoiceExpression = attrs.uiLockChoice;
Expand All @@ -30,6 +30,7 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) {

if($select.multiple){
$select.sizeSearchInput();
$select.onMatchSelectCallback = $parse(attrs.onMatchSelect);
}

}
Expand Down
15 changes: 15 additions & 0 deletions src/uiSelectMultipleDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
return true;
};

// Fire onMatchSelect when a match is selected from ui-select-matches list.
ctrl.selectMatch = function(index) {
ctrl.activeMatchIndex = index;
var locals = {},
selectedMatch = $select.selected[index];

locals[$select.parserResult.itemName] = selectedMatch;

if($select.onMatchSelectCallback) {
$select.onMatchSelectCallback($scope, {
$item: selectedMatch,
$model: $select.parserResult.modelMapper($scope, locals)
});
}
};

}],
controllerAs: '$selectMultiple',
Expand Down