Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 507d9f2

Browse files
author
Robert Miller
authored
Merge pull request #19 from LukaszKokot/feature/allow-not-trimming
Add option for not trimming input value
2 parents 0325aee + 56138c4 commit 507d9f2

15 files changed

+99
-26
lines changed

dist/select.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.8 - 2017-12-20T18:40:38.492Z
4+
* Version: 0.19.8 - 2020-01-17T13:11:27.917Z
55
* License: MIT
66
*/
77

dist/select.js

Lines changed: 23 additions & 14 deletions
Large diffs are not rendered by default.

dist/select.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/select-multiple.tpl.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
aria-expanded="{{$select.open}}"
1616
aria-label="{{$select.baseTitle}}"
1717
ng-class="{'spinner': $select.refreshing}"
18+
ng-trim="{{ $select.trim }}"
1819
ondrop="return false;">
1920
<input type="text"
2021
tabindex="-1"

src/bootstrap/select.tpl.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
ng-class="{ 'ui-select-search-hidden' : !$select.searchEnabled }"
1010
placeholder="{{$select.placeholder}}"
1111
ng-model="$select.search"
12-
ng-show="$select.open">
12+
ng-show="$select.open"
13+
ng-trim="{{ $select.trim }}">
1314
<div class="ui-select-choices"></div>
1415
<div class="ui-select-no-choice"></div>
1516
</div>

src/common.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ var uis = angular.module('ui.select', [])
131131
appendDropdownToBody: false,
132132
spinnerEnabled: false,
133133
spinnerClass: 'glyphicon glyphicon-refresh ui-select-spin',
134-
backspaceReset: true
134+
backspaceReset: true,
135+
trim: true
135136
})
136137

137138
// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913

src/select2/select-multiple.tpl.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ng-hide="$select.disabled"
2222
ng-model="$select.search"
2323
ng-click="$select.activate()"
24+
ng-trim="{{ $select.trim }}"
2425
style="width: 34px;"
2526
ondrop="return false;">
2627
<input type="text" tabindex="-1"

src/select2/select.tpl.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<input type="search" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
1111
ng-class="{'select2-active': $select.refreshing}"
1212
role="combobox"
13+
ng-trim="{{ $select.trim }}"
1314
aria-expanded="true"
1415
aria-owns="ui-select-choices-{{ $select.generatedId }}"
1516
aria-label="{{ $select.baseTitle }}"

src/selectize/select-multiple.tpl.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
ng-disabled="$select.disabled"
1212
aria-expanded="{{$select.open}}"
1313
aria-label="{{ $select.baseTitle }}"
14+
ng-trim="{{ $select.trim }}"
1415
ondrop="return false;">
1516
<input type="text" tabindex="-1"
1617
class="ui-select-copy-input ui-select-offscreen">
1718
</div>
1819
<div class="ui-select-choices"></div>
1920
<div class="ui-select-no-choice"></div>
20-
</div>
21+
</div>

src/selectize/select.tpl.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
ng-model="$select.search"
1212
ng-hide="!$select.isEmpty() && !$select.open"
1313
ng-disabled="$select.disabled"
14+
ng-trim="{{ $select.trim }}"
1415
aria-label="{{ $select.baseTitle }}">
1516
</div>
1617
<div class="ui-select-choices"></div>

src/uiSelectController.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,14 @@ uis.controller('uiSelectCtrl',
633633
// and remove tagging token if it's the last character in string
634634
var chunks = search.split(ctrl.taggingTokenEscape + token);
635635
chunks.push(chunks.pop().replace(tokenRegex, ''));
636-
search = chunks.join(token).trim();
636+
search = chunks.join(token);
637637
} else {
638638
// remove tagging token if it's the last character
639-
search = search.replace(tokenRegex, '').trim();
639+
search = search.replace(tokenRegex, '');
640+
}
641+
642+
if ( !!$scope.$select.trim ) {
643+
search = search.trim();
640644
}
641645
return search;
642646
}

src/uiSelectDirective.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ uis.directive('uiSelect',
181181
$select.appendDropdownToBody = appendDropdownToBody !== undefined ? appendDropdownToBody : uiSelectConfig.appendDropdownToBody;
182182
});
183183

184+
scope.$watch(function () { return scope.$eval(attrs.trim); }, function(newVal) {
185+
$select.trim = newVal !== undefined ? newVal : uiSelectConfig.trim;
186+
});
187+
184188
//Automatically gets focus when loaded
185189
if (angular.isDefined(attrs.autofocus)){
186190
$timeout(function(){

test/select.spec.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ describe('ui-select tests', function () {
181181
if (attrs.backspaceReset !== undefined) { attrsHtml += ' backspace-reset="' + attrs.backspaceReset + '"'; }
182182
if (attrs.uiDisableChoice !== undefined) { choicesAttrsHtml += ' ui-disable-choice="' + attrs.uiDisableChoice + '"'; }
183183
if (attrs.removeSelected !== undefined) { attrsHtml += ' remove-selected="' + attrs.removeSelected + '"'; }
184+
if (attrs.trim !== undefined) { attrsHtml += ' trim="' + attrs.trim + '"'; }
184185
}
185186

186187
return compileTemplate(
@@ -1139,7 +1140,7 @@ describe('ui-select tests', function () {
11391140
var el = createUiSelect();
11401141
expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function () {
11411142
return this.textContent;
1142-
}).toArray()).toEqual(["Foo", "Baz", "bar"]);
1143+
}).toArray()).toEqual(["Foo", "bar", "Baz"]);
11431144
});
11441145
});
11451146

@@ -3680,6 +3681,54 @@ describe('ui-select tests', function () {
36803681
});
36813682
});
36823683

3684+
describe('Test trim', function () {
3685+
it('should have a default value of true', function () {
3686+
var control = createUiSelect();
3687+
expect(control.scope().$select.trim).toEqual(true);
3688+
});
3689+
3690+
it('should have set a value of false', function () {
3691+
var control = createUiSelect({ trim: false });
3692+
expect(control.scope().$select.trim).toEqual(false);
3693+
});
3694+
3695+
['selectize', 'bootstrap', 'select2'].forEach(function (theme) {
3696+
describe(theme + ' theme', function () {
3697+
it('should define ng-trim to true when undefined', function () {
3698+
var el = createUiSelect({ theme});
3699+
expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('true');
3700+
});
3701+
3702+
it('should define ng-trim when true', function () {
3703+
var el = createUiSelect({ theme, trim: true });
3704+
expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('true');
3705+
});
3706+
3707+
it('should define ng-trim when false', function () {
3708+
var el = createUiSelect({ theme, trim: false });
3709+
expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('false');
3710+
});
3711+
3712+
describe('multiple', function () {
3713+
it('should define ng-trim to true when undefined', function () {
3714+
var el = createUiSelect({ multiple: 'multiple', theme });
3715+
expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('true');
3716+
});
3717+
3718+
it('should define ng-trim when true', function () {
3719+
var el = createUiSelect({ multiple: 'multiple', theme, trim: true });
3720+
expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('true');
3721+
});
3722+
3723+
it('should define ng-trim when false', function () {
3724+
var el = createUiSelect({ multiple: 'multiple', theme, trim: false });
3725+
expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('false');
3726+
});
3727+
});
3728+
});
3729+
});
3730+
});
3731+
36833732
describe('With refresh on active', function () {
36843733
it('should refresh when is activated', function () {
36853734
scope.fetchFromServer = function () { };

0 commit comments

Comments
 (0)