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

feat: add trim option #2157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
252 changes: 177 additions & 75 deletions dist/select.css

Large diffs are not rendered by default.

271 changes: 212 additions & 59 deletions dist/select.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/select.min.css

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

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

Large diffs are not rendered by default.

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.

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 ng-show="$select.open && $select.items.length > 0" class="ui-select-dropdown dropdown-menu">
<div class="ui-select-header"></div>
<div class="ui-select-choices"></div>
Expand Down
3 changes: 2 additions & 1 deletion src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ var uis = angular.module('ui.select', [])
appendToBody: 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.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div class="search-container" ng-class="{'ui-select-search-hidden':!$select.searchEnabled, 'select2-search':$select.searchEnabled}">
<input type="search" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
ng-class="{'select2-active': $select.refreshing}"
ng-trim="{{ $select.trim }}"
role="combobox"
aria-expanded="true"
aria-owns="ui-select-choices-{{ $select.generatedId }}"
Expand Down
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 ng-show="$select.open" class="ui-select-dropdown selectize-dropdown"
Expand Down
4 changes: 4 additions & 0 deletions src/uiSelectDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ uis.directive('uiSelect',
$select.spinnerClass = spinnerClass !== undefined ? attrs.spinnerClass : uiSelectConfig.spinnerClass;
});

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
49 changes: 49 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,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 @@ -3494,6 +3495,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: theme });
expect($(el).find('.ui-select-search').attr('ng-trim')).toEqual('true');
});

it('should define ng-trim when true', function () {
var el = createUiSelect({ theme: 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: 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: 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: 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: 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