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

Commit

Permalink
feat: add trim option
Browse files Browse the repository at this point in the history
Closes #2064
  • Loading branch information
Clement Teule committed Aug 29, 2018
1 parent a5e9380 commit 5c86280
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 13 deletions.
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 - 2018-08-29T05:34:50.133Z
* Version: 0.19.8 - 2018-08-29T05:41:58.530Z
* License: MIT
*/

Expand Down
15 changes: 10 additions & 5 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.

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});
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

0 comments on commit 5c86280

Please sign in to comment.