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

Commit 9f13358

Browse files
committed
Merge pull request #325 from ravensteel/master
If 'search-enabled' attribute is missing, use value, defined in 'uiSelectConfig.searchEnabled' instead of hard-coded 'true'
2 parents fb04dca + a1d9e63 commit 9f13358

File tree

2 files changed

+86
-26
lines changed

2 files changed

+86
-26
lines changed

src/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@
748748

749749
scope.$watch('searchEnabled', function() {
750750
var searchEnabled = scope.$eval(attrs.searchEnabled);
751-
$select.searchEnabled = searchEnabled !== undefined ? searchEnabled : true;
751+
$select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled;
752752
});
753753

754754
attrs.$observe('disabled', function() {

test/select.spec.js

Lines changed: 85 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
describe('ui-select tests', function() {
4-
var scope, $rootScope, $compile, $timeout;
4+
var scope, $rootScope, $compile, $timeout, $injector;
55

66
var Key = {
77
Enter: 13,
@@ -16,13 +16,14 @@ describe('ui-select tests', function() {
1616
};
1717

1818
beforeEach(module('ngSanitize', 'ui.select'));
19-
beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_) {
19+
beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_, _$injector_) {
2020
$rootScope = _$rootScope_;
2121
scope = $rootScope.$new();
2222
$compile = _$compile_;
2323
$timeout = _$timeout_;
24+
$injector = _$injector_;
2425
scope.selection = {};
25-
26+
2627
scope.getGroupLabel = function(person) {
2728
return person.age % 2 ? 'even' : 'odd';
2829
};
@@ -208,7 +209,7 @@ describe('ui-select tests', function() {
208209
var el = createUiSelect({theme : 'select2'});
209210
var searchInput = el.find('.ui-select-search');
210211
var $select = el.scope().$select;
211-
212+
212213
expect($select.open).toEqual(false);
213214

214215
el.find(".ui-select-toggle").click();
@@ -485,9 +486,9 @@ describe('ui-select tests', function() {
485486
el.scope().$select.search = 't';
486487
scope.$digest();
487488
var choices = el.find('.ui-select-choices-row');
488-
489+
489490
openDropdown(el);
490-
491+
491492
expect(choices.eq(0)).toHaveClass('active');
492493
expect(getGroupLabel(choices.eq(0)).text()).toBe('Foo');
493494

@@ -571,7 +572,7 @@ describe('ui-select tests', function() {
571572
clickItem(el, 'Samantha');
572573
expect(scope.selection.selected).toBe(scope.people[5]);
573574
});
574-
575+
575576
it('should parse the model correctly using alias', function() {
576577
var el = compileTemplate(
577578
'<ui-select ng-model="selection.selected"> \
@@ -586,7 +587,7 @@ describe('ui-select tests', function() {
586587
scope.$digest();
587588
expect(getMatchLabel(el)).toEqual('Samantha');
588589
});
589-
590+
590591
it('should format the model correctly using property of alias', function() {
591592
var el = compileTemplate(
592593
'<ui-select ng-model="selection.selected"> \
@@ -600,7 +601,7 @@ describe('ui-select tests', function() {
600601
clickItem(el, 'Samantha');
601602
expect(scope.selection.selected).toBe('Samantha');
602603
});
603-
604+
604605
it('should parse the model correctly using property of alias', function() {
605606
var el = compileTemplate(
606607
'<ui-select ng-model="selection.selected"> \
@@ -615,7 +616,7 @@ describe('ui-select tests', function() {
615616
scope.$digest();
616617
expect(getMatchLabel(el)).toEqual('Samantha');
617618
});
618-
619+
619620
it('should parse the model correctly using property of alias with async choices data', function() {
620621
var el = compileTemplate(
621622
'<ui-select ng-model="selection.selected"> \
@@ -654,13 +655,13 @@ describe('ui-select tests', function() {
654655
scope.$digest();
655656
expect(getMatchLabel(el)).toEqual('Samantha');
656657
});
657-
658+
658659
it('should format the model correctly without alias', function() {
659660
var el = createUiSelect();
660661
clickItem(el, 'Samantha');
661662
expect(scope.selection.selected).toBe(scope.people[5]);
662663
});
663-
664+
664665
it('should parse the model correctly without alias', function() {
665666
var el = createUiSelect();
666667
scope.selection.selected = scope.people[5];
@@ -922,8 +923,8 @@ describe('ui-select tests', function() {
922923
scope.fetchFromServer = function(searching){
923924

924925
if (searching == 's')
925-
return scope.people
926-
926+
return scope.people
927+
927928
if (searching == 'o'){
928929
scope.people = []; //To simulate cases were previously selected item isnt in the list anymore
929930
}
@@ -958,12 +959,12 @@ describe('ui-select tests', function() {
958959
describe('selectize theme', function() {
959960

960961
it('should show search input when true', function() {
961-
setupSelectComponent('true', 'selectize');
962+
setupSelectComponent(true, 'selectize');
962963
expect($(el).find('.ui-select-search')).not.toHaveClass('ng-hide');
963964
});
964965

965966
it('should hide search input when false', function() {
966-
setupSelectComponent('false', 'selectize');
967+
setupSelectComponent(false, 'selectize');
967968
expect($(el).find('.ui-select-search')).toHaveClass('ng-hide');
968969
});
969970

@@ -1031,7 +1032,7 @@ describe('ui-select tests', function() {
10311032
});
10321033

10331034
it('should set model as an empty array if ngModel isnt defined', function () {
1034-
1035+
10351036
// scope.selection.selectedMultiple = [];
10361037
var el = createUiSelectMultiple();
10371038

@@ -1117,7 +1118,7 @@ describe('ui-select tests', function() {
11171118
triggerKeydown(searchInput, Key.Left);
11181119
triggerKeydown(searchInput, Key.Backspace);
11191120
expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[6]]); //Wladimir & Nicole
1120-
1121+
11211122
expect(el.scope().$select.activeMatchIndex).toBe(0);
11221123

11231124
});
@@ -1133,7 +1134,7 @@ describe('ui-select tests', function() {
11331134
triggerKeydown(searchInput, Key.Left);
11341135
triggerKeydown(searchInput, Key.Delete);
11351136
expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[6]]); //Wladimir & Nicole
1136-
1137+
11371138
expect(el.scope().$select.activeMatchIndex).toBe(1);
11381139

11391140
});
@@ -1348,7 +1349,7 @@ describe('ui-select tests', function() {
13481349
});
13491350

13501351
it('should format view value correctly when using single property binding and refresh funcion', function () {
1351-
1352+
13521353
scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com'];
13531354

13541355
var el = compileTemplate(
@@ -1367,8 +1368,8 @@ describe('ui-select tests', function() {
13671368
scope.fetchFromServer = function(searching){
13681369

13691370
if (searching == 'n')
1370-
return scope.people
1371-
1371+
return scope.people
1372+
13721373
if (searching == 'o'){
13731374
scope.people = []; //To simulate cases were previously selected item isnt in the list anymore
13741375
}
@@ -1389,7 +1390,7 @@ describe('ui-select tests', function() {
13891390
});
13901391

13911392
it('should watch changes for $select.selected and update formatted value correctly', function () {
1392-
1393+
13931394
scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com'];
13941395

13951396
var el = compileTemplate(
@@ -1418,7 +1419,7 @@ describe('ui-select tests', function() {
14181419
});
14191420

14201421
it('should change viewvalue only once when updating modelvalue', function () {
1421-
1422+
14221423
scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com'];
14231424

14241425
var el = compileTemplate(
@@ -1445,7 +1446,7 @@ describe('ui-select tests', function() {
14451446

14461447

14471448
it('should run $formatters when changing model directly', function () {
1448-
1449+
14491450
scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com'];
14501451

14511452
var el = compileTemplate(
@@ -1472,5 +1473,64 @@ describe('ui-select tests', function() {
14721473
});
14731474
});
14741475

1476+
describe('default configuration via uiSelectConfig', function() {
1477+
1478+
describe('searchEnabled option', function() {
14751479

1480+
function setupWithoutAttr(){
1481+
return compileTemplate(
1482+
'<ui-select ng-model="selection.selected"> \
1483+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1484+
<ui-select-choices repeat="person in people | filter: $select.search"> \
1485+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1486+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1487+
</ui-select-choices> \
1488+
</ui-select>'
1489+
);
1490+
}
1491+
1492+
function setupWithAttr(searchEnabled){
1493+
return compileTemplate(
1494+
'<ui-select ng-model="selection.selected" search-enabled="'+searchEnabled+'"> \
1495+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1496+
<ui-select-choices repeat="person in people | filter: $select.search"> \
1497+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1498+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1499+
</ui-select-choices> \
1500+
</ui-select>'
1501+
);
1502+
}
1503+
1504+
it('should be true by default', function(){
1505+
var el = setupWithoutAttr();
1506+
expect(el.scope().$select.searchEnabled).toBe(true);
1507+
});
1508+
1509+
it('should disable search if default set to false', function(){
1510+
var uiSelectConfig = $injector.get('uiSelectConfig');
1511+
uiSelectConfig.searchEnabled = false;
1512+
1513+
var el = setupWithoutAttr();
1514+
expect(el.scope().$select.searchEnabled).not.toBe(true);
1515+
});
1516+
1517+
it('should be overridden by inline option search-enabled=true', function(){
1518+
var uiSelectConfig = $injector.get('uiSelectConfig');
1519+
uiSelectConfig.searchEnabled = false;
1520+
1521+
var el = setupWithAttr(true);
1522+
expect(el.scope().$select.searchEnabled).toBe(true);
1523+
});
1524+
1525+
it('should be overridden by inline option search-enabled=false', function(){
1526+
var uiSelectConfig = $injector.get('uiSelectConfig');
1527+
uiSelectConfig.searchEnabled = true;
1528+
1529+
var el = setupWithAttr(false);
1530+
expect(el.scope().$select.searchEnabled).not.toBe(true);
1531+
});
1532+
1533+
});
1534+
1535+
});
14761536
});

0 commit comments

Comments
 (0)