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

Allow creating new tags in multiple select mode. #226

Closed
wants to merge 3 commits 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
23 changes: 23 additions & 0 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,29 @@
e.preventDefault();
e.stopPropagation();
}

// In multiple select (tag) mode, when Enter key pressed and tag doesn't exist, add it.
if (ctrl.multiple && !processed && (key == KEY.ENTER)) {
e.preventDefault();
e.stopPropagation();

var matchFound = false;

// Disallow duplicate tags (not case sensitive).
angular.forEach(ctrl.selected, function(value) {
if (ctrl.search == value) {
matchFound = true;
return false;
}
});

if (!matchFound) {
ctrl.selected.push(ctrl.search);
_resetSearchInput();
ctrl.sizeSearchInput();
}
}

});

if(KEY.isVerticalMovement(key) && ctrl.items.length > 0){
Expand Down
2 changes: 1 addition & 1 deletion src/select2/match-multiple.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<li class="ui-select-match-item select2-search-choice" ng-repeat="$item in $select.selected"
ng-class="{'select2-search-choice-focus':$select.activeMatchIndex === $index}">
<span uis-transclude-append></span>
<a href="#" class="ui-select-match-close select2-search-choice-close" ng-click="$select.removeChoice($index)" tabindex="-1"></a>
<a href="" class="ui-select-match-close select2-search-choice-close" ng-click="$select.removeChoice($index)" tabindex="-1"></a>
</li>
</span>