-1){s=n.split(a);break}}0===s.length&&(s=[n]);var o=E.search;angular.forEach(s,function(e){var t=E.tagging.fct?E.tagging.fct(e):e;t&&E.select(t,!0)}),E.search=o||C,e.preventDefault(),e.stopPropagation()}}),E.searchInput.on("blur",function(e){if(E.tagging.isActivated&&E.tagOnBlur&&E.search){var t=e.relatedTarget||e.explicitOriginalTarget||document.activeElement;if(E.uiSelectChoices[0].contains(t))return;c(function(){E.searchInput.triggerHandler("tagged");var e=w(E.search);E.tagging.fct&&(e=E.tagging.fct(e)),e&&E.select(e,!0)})}}),E.searchInput.on("tagged",function(){c(function(){g()})});var M=l(function(){E.sizeSearchInput()},50);angular.element(p).bind("resize",M),t.$on("$destroy",function(){E.searchInput.off("keyup keydown tagged blur paste"),angular.element(p).off("resize",M)}),t.$watch("$select.activeIndex",function(e){e&&n.find("input").attr("aria-activedescendant","ui-select-choices-row-"+E.generatedId+"-"+e)}),t.$watch("$select.open",function(e){e||n.find("input").removeAttr("aria-activedescendant")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,i,n,c,s,l,a){return{restrict:"EA",templateUrl:function(e,t){var n=t.theme||i.theme;return n+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(s,o){var r=/{(.*)}\s*{(.*)}/.exec(o.ngClass);if(r){var u="{"+r[1]+", "+r[2]+"}";o.ngClass=u,s.attr("ng-class",u)}return angular.isDefined(o.multiple)?s.append("").removeAttr("multiple"):s.append(""),o.inputId&&(s.querySelectorAll("input.ui-select-search")[0].id=o.inputId),function(s,o,r,u,d){function p(e){if($.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!$.clickTriggeredSelect){var i;if($.skipFocusser)i=!0;else{var n=["input","button","textarea","select"],c=angular.element(e.target).controller("uiSelect");i=c&&c!==$,i||(i=~n.indexOf(e.target.tagName.toLowerCase()))}$.close(i),s.$digest()}$.clickTriggeredSelect=!1}}function h(){var t=c(o);w=angular.element(''),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",o.after(w),x=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function g(){null!==w&&(w.replaceWith(o),w=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=x,$.setFocus())}function f(){$.appendDropdownToBody&&($.open?v():m())}function v(){if($.appendDropdownToBody&&(M=angular.element(o).querySelectorAll(".ui-select-dropdown"),M.length)){R=M.parent(),D=angular.element(""),D.addClass("ui-select-dropdown-container ui-select-container"),D.append(M),e.find("body").append(D);var t=c(R);M.css("position","absolute"),M.css("left",t.left+"px"),M.css("top",t.top+t.height+"px"),M.css("width",t.width+"px"),M.css("display","block"),$.uiSelectChoices=angular.element(M[0])}}function m(){$.appendDropdownToBody&&M&&M.length&&R&&D&&(R.append(M),M.css("position",""),M.css("left",""),M.css("top",""),M.css("width",""),M.css("display",""),$.uiSelectChoices=angular.element(M[0]),D.remove(),D=null)}var $=u[0],b=u[1];$.generatedId=i.generateId(),$.baseTitle=r.title||"Select box",$.focusserTitle=$.baseTitle+" focus",$.focusserId="focusser-"+$.generatedId,$.closeOnSelect=function(){return angular.isDefined(r.closeOnSelect)?l(r.closeOnSelect)():i.closeOnSelect}(),s.$watch("skipFocusser",function(){var e=s.$eval(r.skipFocusser);$.skipFocusser=void 0!==e?e:i.skipFocusser}),$.onSelectCallback=l(r.onSelect),$.onRemoveCallback=l(r.onRemove),$.ngModel=b,$.choiceGrouped=function(e){return $.isGrouped&&e&&e.name},r.tabindex&&r.$observe("tabindex",function(e){$.focusInput.attr("tabindex",e),o.removeAttr("tabindex")}),s.$watch(function(){return s.$eval(r.searchEnabled)},function(e){$.searchEnabled=void 0!==e?e:i.searchEnabled}),s.$watch("sortable",function(){var e=s.$eval(r.sortable);$.sortable=void 0!==e?e:i.sortable}),r.$observe("backspaceReset",function(){var e=s.$eval(r.backspaceReset);$.backspaceReset=void 0===e||e}),r.$observe("limit",function(){$.limit=angular.isDefined(r.limit)?parseInt(r.limit,10):void 0}),s.$watch("removeSelected",function(){var e=s.$eval(r.removeSelected);$.removeSelected=void 0!==e?e:i.removeSelected}),r.$observe("disabled",function(){$.disabled=void 0!==r.disabled&&r.disabled}),r.$observe("resetSearchInput",function(){var e=s.$eval(r.resetSearchInput);$.resetSearchInput=void 0===e||e}),r.$observe("paste",function(){$.paste=s.$eval(r.paste)}),r.$observe("copying",function(){$.copying=s.$eval(r.copying)}),r.$observe("tagging",function(){if(void 0!==r.tagging){var e=s.$eval(r.tagging);$.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else $.tagging={isActivated:!1,fct:void 0}}),r.$observe("taggingLabel",function(){void 0!==r.tagging&&("false"===r.taggingLabel?$.taggingLabel=!1:$.taggingLabel=void 0!==r.taggingLabel?r.taggingLabel:"(new)")}),r.$observe("taggingTokens",function(){if(void 0!==r.tagging){var e=void 0!==r.taggingTokens?r.taggingTokens.split("|"):[",","ENTER"];$.taggingTokens={isActivated:!0,tokens:e}}}),r.$observe("taggingTokenEscape",function(){void 0!==r.tagging&&($.taggingTokenEscape=r.taggingTokenEscape)}),r.$observe("tagOnBlur",function(){$.tagOnBlur=s.$eval(r.tagOnBlur)===!0}),r.$observe("spinnerEnabled",function(){var e=s.$eval(r.spinnerEnabled);$.spinnerEnabled=void 0!==e?e:i.spinnerEnabled}),r.$observe("spinnerClass",function(){var e=r.spinnerClass;$.spinnerClass=void 0!==e?r.spinnerClass:i.spinnerClass}),r.$observe("appendDropdownToBody",function(){var e=s.$eval(r.appendDropdownToBody);$.appendDropdownToBody=void 0!==e?e:i.appendDropdownToBody}),angular.isDefined(r.autofocus)&&a(function(){$.setFocus()}),angular.isDefined(r.focusOn)&&s.$on(r.focusOn,function(){a(function(){$.setFocus()})}),e.on("click",p),s.$on("$destroy",function(){e.off("click",p)}),d(s,function(e){var t=angular.element("").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);o.querySelectorAll(".ui-select-match").replaceWith(i);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c);var s=t.querySelectorAll(".ui-select-no-choice");s.removeAttr("ui-select-no-choice"),s.removeAttr("data-ui-select-no-choice"),1==s.length&&o.querySelectorAll(".ui-select-no-choice").replaceWith(s)});var y=s.$eval(r.appendToBody);(void 0!==y?y:i.appendToBody)&&(s.$watch("$select.open",function(e){e?h():g()}),s.$on("$destroy",function(){g()}));var w=null,x="",E=null,C="direction-up";s.$watch("$select.open",function(){"auto"!==$.dropdownPosition&&"up"!==$.dropdownPosition||s.calculateDropdownPos()});var S=function(e,t){e=e||c(o),t=t||c(E);var i=t.height*-1;$.appendDropdownToBody&&(i=e.top-t.height),E[0].style.position="absolute",E[0].style.top=i+"px",o.addClass(C)},I=function(e,t){o.removeClass(C),e=e||c(o),t=t||c(E),$.appendDropdownToBody||(E[0].style.position="",E[0].style.top="")},A=function(){a(function(){if("up"===$.dropdownPosition)S();else{o.removeClass(C);var t=c(o),i=c(E),n=e[0].documentElement.scrollTop||e[0].body.scrollTop;t.top+t.height+i.height>n+e[0].documentElement.clientHeight?S(t,i):I(t,i)}E[0].style.opacity=1})},k=!1;s.calculateDropdownPos=function(){if($.open){if(E=angular.element(o).querySelectorAll(".ui-select-dropdown"),$.appendDropdownToBody&&0===E.length&&(E=M),0===E.length)return;if(""!==$.search||k||(E[0].style.opacity=0,k=!0),!c(E).height&&$.$animate&&$.$animate.on&&$.$animate.enabled(E)){var e=!0;$.$animate.on("enter",E,function(t,i){"close"===i&&e&&(A(),e=!1)})}else A()}else{if(null===E||0===E.length)return;E[0].style.opacity=0,E[0].style.position="",E[0].style.top="",o.removeClass(C)}},s.$watch("$select.open",function(){f()}),s.$on("$destroy",function(){$.appendDropdownToBody&&m()});var T=angular.element(t(o[0]));T&&T.on("scroll",function(){$.appendDropdownToBody&&$.open&&a(function(){$.close($.skipFocusser)})});var M=null,D=null,R=null;$.rePositionOnlyDropdown=function(){m(),f()}}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){function t(e,t){return e[0].hasAttribute(t)?e.attr(t):e[0].hasAttribute("data-"+t)?e.attr("data-"+t):e[0].hasAttribute("x-"+t)?e.attr("x-"+t):void 0}return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(i){i.addClass("ui-select-match");var n=i.parent(),c=t(n,"theme")||e.theme,s=angular.isDefined(t(n,"multiple"));return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,i,n,c){function s(e){c.allowClear=!!angular.isDefined(e)&&(""===e||"true"===e.toLowerCase())}c.lockChoiceExpression=n.uiLockChoice,n.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),n.$observe("allowClear",s),s(n.allowClear),c.multiple&&c.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var i,n=this,c=e.$select;angular.isUndefined(c.selected)&&(c.selected=[]),e.$evalAsync(function(){i=e.ngModel}),n.activeMatchIndex=-1,n.allChoicesActive=!1,n.updateModel=function(){i.$setViewValue(Date.now()),n.refreshComponent()},n.refreshComponent=function(){c.refreshItems&&c.refreshItems(),c.sizeSearchInput&&c.sizeSearchInput(),c.closeOnSelect||c.rePositionOnlyDropdown()},n.removeChoice=function(i){if(c.isLocked(null,i))return!1;var s=c.selected[i],l={};return l[c.parserResult.itemName]=s,c.selected.splice(i,1),n.activeMatchIndex=-1,c.sizeSearchInput(),t(function(){c.onRemoveCallback(e,{$item:s,$model:c.parserResult.modelMapper(e,l)})}),n.updateModel(),!0},n.removeAllChoices=function(){return c.selected=[],n.activeMatchIndex=-1,n.allChoicesActive=!1,c.sizeSearchInput(),n.updateModel(),!0},n.isActiveChoice=function(e){return n.allChoicesActive||n.activeMatchIndex===e},n.getPlaceholder=function(){if(!c.selected||!c.selected.length)return c.placeholder}}],controllerAs:"$selectMultiple",link:function(c,s,l,a){function o(e,t){var n=e.which;c.$apply(function(){var c=!1,s=i.isHorizontalMovement(n)||i.isMetaAndKey(e,i.A)||i.isMetaAndKey(e,i.X);s?c=u(e):t||(v.allChoicesActive=!1),c&&n!=i.TAB&&(e.preventDefault(),e.stopPropagation())})}function r(e){return angular.isNumber(e.selectionStart)?e.selectionEnd>e.selectionStart?e.selectionEnd:e.selectionStart:e.value.length}function u(e){function t(){return v.allChoicesActive?(v.removeAllChoices(),!1):!!~v.activeMatchIndex&&(v.removeChoice(v.activeMatchIndex),o)}function n(){switch(h){case i.LEFT:return v.allChoicesActive=!1,~v.activeMatchIndex?d:a;case i.RIGHT:return v.allChoicesActive=!1,~v.activeMatchIndex&&o!==a?u:(g.activate(),!1);case i.BACKSPACE:return v.allChoicesActive?(v.removeAllChoices(),!1):~v.activeMatchIndex?v.removeChoice(o)?d:o:a;case i.DELETE:return t();case i.X:if(e.metaKey)return t();break;case i.A:if(e.metaKey)return v.allChoicesActive=!0,!1}}var c=r(g.searchInput[0]),s=g.selected.length,l=0,a=s-1,o=v.activeMatchIndex,u=v.activeMatchIndex+1,d=v.activeMatchIndex-1,p=o,h=e.which;if(c>0||g.search.length&&h==i.RIGHT)return!1;g.close(null,!0),p=n(),g.selected.length&&p!==!1?v.activeMatchIndex=Math.min(a,Math.max(l,p)):v.activeMatchIndex=-1;var f=v.allChoicesActive||v.activeMatchIndex!==-1;if(g.copying&&f){if(g.copyInput[0].focus(),v.allChoicesActive&&g.selected){var m=g.copying(g.selected);g.copyInput.val(m)[0].select()}else if(v.activeMatchIndex>=0){var $=g.selected[v.activeMatchIndex];if($){var b=g.copying([$]);g.copyInput.val(b)[0].select()}}}else g.copying&&!f&&g.setFocus();return!0}function d(e){if(void 0===e||void 0===g.search)return!1;var t=e.filter(function(e){return void 0!==g.search.toUpperCase()&&void 0!==e&&e.toUpperCase()===g.search.toUpperCase()}).length>0;return t}function p(e,t){var i=-1;if(angular.isArray(e))for(var n=angular.copy(e),c=0;c=0;n--)t={},t[g.parserResult.itemName]=g.selected[n],e=g.parserResult.modelMapper(c,t),i.unshift(e);return i}),f.$formatters.unshift(function(e){var t,i=g.parserResult&&g.parserResult.source(c,{$select:{search:""}}),n={};if(!i)return e;var s=[],l=function(e,i){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(n[g.parserResult.itemName]=e[l],t=g.parserResult.modelMapper(c,n),g.parserResult.trackByExp){var a=/(\w*)\./.exec(g.parserResult.trackByExp),o=/\.([^\s]+)/.exec(g.parserResult.trackByExp);if(a&&a.length>0&&a[1]==g.parserResult.itemName&&o&&o.length>0&&t[o[1]]==i[o[1]])return s.unshift(e[l]),!0}if(angular.equals(t,i))return s.unshift(e[l]),!0}return!1}};if(!e)return s;for(var a=e.length-1;a>=0;a--)l(g.selected,e[a])||l(i,e[a])||s.unshift(e[a]);return s}),c.$watchCollection(function(){return f.$modelValue},function(e,t){t!=e&&(angular.isDefined(f.$modelValue)&&(f.$modelValue=null),v.refreshComponent())}),f.$render=function(){if(!angular.isArray(f.$viewValue)){if(!e(f.$viewValue))throw t("multiarr","Expected model value to be array but got '{0}'",f.$viewValue);f.$viewValue=[]}g.selected=f.$viewValue,v.refreshComponent(),c.$evalAsync()},c.$on("uis:select",function(e,t){if(!(g.selected.length>=g.limit)){g.selected.push(t);var i={};i[g.parserResult.itemName]=t,n(function(){g.onSelectCallback(c,{$item:t,$model:g.parserResult.modelMapper(c,i)})}),v.updateModel()}}),c.$on("uis:select-multiple",function(e,t){g.selected.length>=g.limit||(g.selected=g.selected.concat(t),v.updateModel())}),c.$on("uis:activate",function(){v.allChoicesActive=!1,v.activeMatchIndex=-1}),c.$watch("$select.disabled",function(e,t){t&&!e&&g.sizeSearchInput()}),g.searchInput.on("keydown",function(e){o(e,!1)}),g.copyInput.on("keydown",function(e){o(e,!0)}),g.searchInput.on("keyup",function(e){if(i.isVerticalMovement(e.which)||c.$evalAsync(function(){g.activeIndex=g.taggingLabel===!1?-1:0}),g.tagging.isActivated&&g.search.length>0){if(e.which===i.TAB||i.isControl(e)||i.isFunctionKey(e)||e.which===i.ESC||i.isVerticalMovement(e.which))return;if(g.activeIndex=g.taggingLabel===!1?-1:0,g.taggingLabel===!1)return;var t,n,s,l,a=angular.copy(g.items),o=angular.copy(g.items),r=!1,u=-1;if(void 0!==g.tagging.fct){if(s=g.$filter("filter")(a,{isTag:!0}),s.length>0&&(l=s[0]),a.length>0&&l&&(r=!0,a=a.slice(1,a.length),o=o.slice(1,o.length)),t=g.tagging.fct(g.search),o.some(function(e){return angular.equals(e,t)})||g.selected.some(function(e){return angular.equals(e,t)}))return void c.$evalAsync(function(){g.activeIndex=0,g.items=a});t&&(t.isTag=!0)}else{if(s=g.$filter("filter")(a,function(e){return e.match(g.taggingLabel)}),s.length>0&&(l=s[0]),n=a[0],void 0!==n&&a.length>0&&l&&(r=!0,a=a.slice(1,a.length),o=o.slice(1,o.length)),t=g.search+" "+g.taggingLabel,p(g.selected,g.search)>-1)return;if(d(o.concat(g.selected)))return void(r&&(a=o,c.$evalAsync(function(){g.activeIndex=0,g.items=a})));if(d(o))return void(r&&(g.items=o.slice(1,o.length)))}r&&(u=p(g.selected,t)),u>-1?a=a.slice(u+1,a.length-1):(a=[],t&&a.push(t),a=a.concat(o)),c.$evalAsync(function(){if(g.activeIndex=0,g.items=a,g.isGrouped){var e=t?a.slice(1):a;g.setItemsFn(e),t&&(g.items.unshift(t),g.groups.unshift({name:"",items:[t],tagging:!0}))}})}}),g.searchInput.on("blur",function(e){h(g.copyInput)}),g.copyInput.on("blur",function(e){h(g.searchInput)})}}}]),c.directive("uiSelectNoChoice",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){t.addClass("ui-select-no-choice");var i=t.parent().attr("theme")||e.theme;return i+"/no-choice.tpl.html"}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(c,s,l,a){
-var o=a[0],r=a[1];r.$parsers.unshift(function(t){if(e(t))return t;var i,n={};return n[o.parserResult.itemName]=t,i=o.parserResult.modelMapper(c,n)}),r.$formatters.unshift(function(t){if(e(t))return t;var i,n=o.parserResult&&o.parserResult.source(c,{$select:{search:""}}),s={};if(n){var l=function(e){return s[o.parserResult.itemName]=e,i=o.parserResult.modelMapper(c,s),i===t};if(o.selected&&l(o.selected))return o.selected;for(var a=n.length-1;a>=0;a--)if(l(n[a]))return n[a]}return t}),c.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){o.selected=r.$viewValue},c.$on("uis:select",function(i,n){o.selected=n;var s={};s[o.parserResult.itemName]=n,t(function(){o.onSelectCallback(c,{$item:n,$model:e(n)?n:o.parserResult.modelMapper(c,s)})})}),c.$on("uis:close",function(e,i){t(function(){o.focusser.prop("disabled",!1),i||o.focusser[0].focus()},0,!1)}),c.$on("uis:activate",function(){u.prop("disabled",!0)});var u=angular.element("");n(u)(c),o.focusser=u,o.focusInput=u,s.parent().append(u),u.bind("focus",function(){c.$evalAsync(function(){o.focus=!0})}),u.bind("blur",function(){c.$evalAsync(function(){o.focus=!1})}),u.bind("keydown",function(e){return e.which===i.BACKSPACE&&o.backspaceReset!==!1?(e.preventDefault(),e.stopPropagation(),o.select(void 0),void c.$apply()):void(e.which===i.TAB||i.isControl(e)||i.isFunctionKey(e)||e.which===i.ESC||(e.which!=i.DOWN&&e.which!=i.UP&&e.which!=i.ENTER&&e.which!=i.SPACE||(e.preventDefault(),e.stopPropagation(),o.activate()),c.$digest()))}),u.bind("keyup input",function(e){e.which===i.TAB||i.isControl(e)||i.isFunctionKey(e)||e.which===i.ESC||e.which==i.ENTER||e.which===i.BACKSPACE||(o.activate(u.val()),u.val(""),c.$digest())})}}}]),c.directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,i){return{require:["^^uiSelect","^ngModel"],link:function(t,n,c,s){if(null===t[c.uiSelectSort])throw i("sort","Expected a list to sort");var l=s[0],a=s[1],o=angular.extend({axis:"horizontal"},t.$eval(c.uiSelectSortOptions)),r=o.axis,u="dragging",d="dropping",p="dropping-before",h="dropping-after";t.$watch(function(){return l.sortable},function(e){e?n.attr("draggable",!0):n.removeAttr("draggable")}),n.on("dragstart",function(e){n.addClass(u),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text",t.$index.toString())}),n.on("dragend",function(){v(u)});var g,f=function(e,t){this.splice(t,0,this.splice(e,1)[0])},v=function(e){angular.forEach(l.$element.querySelectorAll("."+e),function(t){angular.element(t).removeClass(e)})},m=function(e){e.preventDefault();var t="vertical"===r?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t
diff --git a/src/selectize/select.tpl.html b/src/selectize/select.tpl.html
index 14dbeaa46..c5c844774 100644
--- a/src/selectize/select.tpl.html
+++ b/src/selectize/select.tpl.html
@@ -11,6 +11,7 @@
ng-model="$select.search"
ng-hide="!$select.isEmpty() && !$select.open"
ng-disabled="$select.disabled"
+ ng-trim="{{ $select.trim }}"
aria-label="{{ $select.baseTitle }}">
diff --git a/src/uiSelectController.js b/src/uiSelectController.js
index be844aef3..ed8b9ccf0 100644
--- a/src/uiSelectController.js
+++ b/src/uiSelectController.js
@@ -633,10 +633,14 @@ uis.controller('uiSelectCtrl',
// and remove tagging token if it's the last character in string
var chunks = search.split(ctrl.taggingTokenEscape + token);
chunks.push(chunks.pop().replace(tokenRegex, ''));
- search = chunks.join(token).trim();
+ search = chunks.join(token);
} else {
// remove tagging token if it's the last character
- search = search.replace(tokenRegex, '').trim();
+ search = search.replace(tokenRegex, '');
+ }
+
+ if ( !!$scope.$select.trim ) {
+ search = search.trim();
}
return search;
}
diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js
index 99db6f5c8..7f15ff00f 100644
--- a/src/uiSelectDirective.js
+++ b/src/uiSelectDirective.js
@@ -181,6 +181,10 @@ uis.directive('uiSelect',
$select.appendDropdownToBody = appendDropdownToBody !== undefined ? appendDropdownToBody : uiSelectConfig.appendDropdownToBody;
});
+ scope.$watch(function () { return scope.$eval(attrs.trim); }, function(newVal) {
+ $select.trim = newVal !== undefined ? newVal : uiSelectConfig.trim;
+ });
+
//Automatically gets focus when loaded
if (angular.isDefined(attrs.autofocus)){
$timeout(function(){
diff --git a/test/select.spec.js b/test/select.spec.js
index ec8d6d4cb..67abf6d8d 100644
--- a/test/select.spec.js
+++ b/test/select.spec.js
@@ -181,6 +181,7 @@ describe('ui-select tests', function () {
if (attrs.backspaceReset !== undefined) { attrsHtml += ' backspace-reset="' + attrs.backspaceReset + '"'; }
if (attrs.uiDisableChoice !== undefined) { choicesAttrsHtml += ' ui-disable-choice="' + attrs.uiDisableChoice + '"'; }
if (attrs.removeSelected !== undefined) { attrsHtml += ' remove-selected="' + attrs.removeSelected + '"'; }
+ if (attrs.trim !== undefined) { attrsHtml += ' trim="' + attrs.trim + '"'; }
}
return compileTemplate(
@@ -1139,7 +1140,7 @@ describe('ui-select tests', function () {
var el = createUiSelect();
expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function () {
return this.textContent;
- }).toArray()).toEqual(["Foo", "Baz", "bar"]);
+ }).toArray()).toEqual(["Foo", "bar", "Baz"]);
});
});
@@ -3680,6 +3681,54 @@ describe('ui-select tests', function () {
});
});
+ describe('Test trim', function () {
+ it('should have a default value of true', function () {
+ var control = createUiSelect();
+ expect(control.scope().$select.trim).toEqual(true);
+ });
+
+ it('should have set a value of false', function () {
+ var control = createUiSelect({ trim: false });
+ expect(control.scope().$select.trim).toEqual(false);
+ });
+
+ ['selectize', 'bootstrap', 'select2'].forEach(function (theme) {
+ describe(theme + ' theme', function () {
+ it('should define ng-trim to true when undefined', function () {
+ var el = createUiSelect({ theme});
+ expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('true');
+ });
+
+ it('should define ng-trim when true', function () {
+ var el = createUiSelect({ theme, trim: true });
+ expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('true');
+ });
+
+ it('should define ng-trim when false', function () {
+ var el = createUiSelect({ theme, trim: false });
+ expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('false');
+ });
+
+ describe('multiple', function () {
+ it('should define ng-trim to true when undefined', function () {
+ var el = createUiSelect({ multiple: 'multiple', theme });
+ expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('true');
+ });
+
+ it('should define ng-trim when true', function () {
+ var el = createUiSelect({ multiple: 'multiple', theme, trim: true });
+ expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('true');
+ });
+
+ it('should define ng-trim when false', function () {
+ var el = createUiSelect({ multiple: 'multiple', theme, trim: false });
+ expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('false');
+ });
+ });
+ });
+ });
+ });
+
describe('With refresh on active', function () {
it('should refresh when is activated', function () {
scope.fetchFromServer = function () { };