diff --git a/src/select.js b/src/select.js index abbdf8e22..98ea7adc0 100644 --- a/src/select.js +++ b/src/select.js @@ -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){ diff --git a/src/select2/match-multiple.tpl.html b/src/select2/match-multiple.tpl.html index d4a2217e7..85b124cfb 100644 --- a/src/select2/match-multiple.tpl.html +++ b/src/select2/match-multiple.tpl.html @@ -7,6 +7,6 @@