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

Add option for not trimming input value #19

Merged
merged 1 commit into from
Jan 31, 2020
Merged
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 dist/select.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* ui-select
* http://github.com/angular-ui/ui-select
* Version: 0.19.8 - 2017-12-20T18:40:38.492Z
* Version: 0.19.8 - 2020-01-17T13:11:27.917Z
* License: MIT
*/

Expand Down
37 changes: 23 additions & 14 deletions dist/select.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/select.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/select.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/select.min.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/bootstrap/select-multiple.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
aria-expanded="{{$select.open}}"
aria-label="{{$select.baseTitle}}"
ng-class="{'spinner': $select.refreshing}"
ng-trim="{{ $select.trim }}"
ondrop="return false;">
<input type="text"
tabindex="-1"
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/select.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
ng-class="{ 'ui-select-search-hidden' : !$select.searchEnabled }"
placeholder="{{$select.placeholder}}"
ng-model="$select.search"
ng-show="$select.open">
ng-show="$select.open"
ng-trim="{{ $select.trim }}">
<div class="ui-select-choices"></div>
<div class="ui-select-no-choice"></div>
</div>
3 changes: 2 additions & 1 deletion src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ var uis = angular.module('ui.select', [])
appendDropdownToBody: false,
spinnerEnabled: false,
spinnerClass: 'glyphicon glyphicon-refresh ui-select-spin',
backspaceReset: true
backspaceReset: true,
trim: true
})

// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913
Expand Down
1 change: 1 addition & 0 deletions src/select2/select-multiple.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ng-hide="$select.disabled"
ng-model="$select.search"
ng-click="$select.activate()"
ng-trim="{{ $select.trim }}"
style="width: 34px;"
ondrop="return false;">
<input type="text" tabindex="-1"
Expand Down
1 change: 1 addition & 0 deletions src/select2/select.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<input type="search" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
ng-class="{'select2-active': $select.refreshing}"
role="combobox"
ng-trim="{{ $select.trim }}"
aria-expanded="true"
aria-owns="ui-select-choices-{{ $select.generatedId }}"
aria-label="{{ $select.baseTitle }}"
Expand Down
3 changes: 2 additions & 1 deletion src/selectize/select-multiple.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
ng-disabled="$select.disabled"
aria-expanded="{{$select.open}}"
aria-label="{{ $select.baseTitle }}"
ng-trim="{{ $select.trim }}"
ondrop="return false;">
<input type="text" tabindex="-1"
class="ui-select-copy-input ui-select-offscreen">
</div>
<div class="ui-select-choices"></div>
<div class="ui-select-no-choice"></div>
</div>
</div>
1 change: 1 addition & 0 deletions src/selectize/select.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}">
</div>
<div class="ui-select-choices"></div>
Expand Down
8 changes: 6 additions & 2 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/uiSelectDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
51 changes: 50 additions & 1 deletion test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that this line changed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that is weird... @LukaszKokot do you know why this changed?

}).toArray()).toEqual(["Foo", "bar", "Baz"]);
});
});

Expand Down Expand Up @@ -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 () { };
Expand Down