From 9dd859d4cf78015f5401fa4d26f8398647bfd005 Mon Sep 17 00:00:00 2001 From: jverghese Date: Sun, 24 Aug 2014 21:19:04 -0700 Subject: [PATCH 1/3] Add support to disable search feature. --- examples/demo-disable-search.html | 89 +++++++++++++++++++++++++++++++ examples/demo.js | 9 ++++ src/select.js | 7 +++ src/select2/match.tpl.html | 2 +- src/select2/select.tpl.html | 2 +- src/selectize/match.tpl.html | 2 +- src/selectize/select.tpl.html | 2 +- 7 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 examples/demo-disable-search.html diff --git a/examples/demo-disable-search.html b/examples/demo-disable-search.html new file mode 100644 index 000000000..e21c31a5d --- /dev/null +++ b/examples/demo-disable-search.html @@ -0,0 +1,89 @@ + + + + + AngularJS ui-select + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Select2 theme

+

Selected: {{person.selected}}

+ + {{$select.selected.name}} + +
+ + email: {{person.email}} + age: + +
+
+ +

Selectize theme

+

Selected: {{country.selected}}

+ + {{$select.selected.name}} + + + + + + + diff --git a/examples/demo.js b/examples/demo.js index d565c59a9..3827a27f3 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -41,6 +41,7 @@ app.filter('propsFilter', function() { app.controller('DemoCtrl', function($scope, $http, $timeout) { $scope.disabled = undefined; + $scope.searchEnabled = undefined; $scope.enable = function() { $scope.disabled = false; @@ -50,6 +51,14 @@ app.controller('DemoCtrl', function($scope, $http, $timeout) { $scope.disabled = true; }; + $scope.enableSearch = function() { + $scope.searchEnabled = true; + } + + $scope.disableSearch = function() { + $scope.searchEnabled = false; + } + $scope.clear = function() { $scope.person.selected = undefined; $scope.address.selected = undefined; diff --git a/src/select.js b/src/select.js index c46fde87c..dd1c489c4 100644 --- a/src/select.js +++ b/src/select.js @@ -20,6 +20,7 @@ .constant('uiSelectConfig', { theme: 'bootstrap', + searchEnabled: true, placeholder: '', // Empty by default, like HTML tag diff --git a/src/selectize/match.tpl.html b/src/selectize/match.tpl.html index a72e9c26e..dff19ce86 100644 --- a/src/selectize/match.tpl.html +++ b/src/selectize/match.tpl.html @@ -1 +1 @@ -
+
diff --git a/src/selectize/select.tpl.html b/src/selectize/select.tpl.html index bc2436087..34fd4f72c 100644 --- a/src/selectize/select.tpl.html +++ b/src/selectize/select.tpl.html @@ -7,7 +7,7 @@ class="ui-select-search" placeholder="{{$select.placeholder}}" ng-model="$select.search" - ng-hide="$select.selected && !$select.open" + ng-hide="!$select.searchEnabled || ($select.selected && !$select.open)" ng-disabled="$select.disabled">
From 4f1034b5b6f94ebcefc04c69d275a9a26765bc32 Mon Sep 17 00:00:00 2001 From: jverghese Date: Sun, 24 Aug 2014 22:59:59 -0700 Subject: [PATCH 2/3] Add search-enabled option for bootstrap theme. --- examples/demo-disable-search.html | 13 +++++++++++++ src/bootstrap/match.tpl.html | 2 +- src/bootstrap/select.tpl.html | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/demo-disable-search.html b/examples/demo-disable-search.html index e21c31a5d..2b92d02b3 100644 --- a/examples/demo-disable-search.html +++ b/examples/demo-disable-search.html @@ -63,6 +63,19 @@ +

Bootstrap theme

+

Selected: {{person.selected}}

+ + {{$select.selected.name}} + +
+ + email: {{person.email}} + age: + +
+
+

Select2 theme

Selected: {{person.selected}}

diff --git a/src/bootstrap/match.tpl.html b/src/bootstrap/match.tpl.html index 10506fb07..2f9ed340a 100644 --- a/src/bootstrap/match.tpl.html +++ b/src/bootstrap/match.tpl.html @@ -3,7 +3,7 @@ ng-disabled="$select.disabled" ng-class="{'btn-default-focus':$select.focus}"; ng-click="$select.activate()"> - {{$select.placeholder}} + {{$select.placeholder}} diff --git a/src/bootstrap/select.tpl.html b/src/bootstrap/select.tpl.html index a8681c9b3..4cec1a311 100644 --- a/src/bootstrap/select.tpl.html +++ b/src/bootstrap/select.tpl.html @@ -4,6 +4,6 @@ class="form-control ui-select-search" placeholder="{{$select.placeholder}}" ng-model="$select.search" - ng-show="$select.open"> + ng-show="$select.searchEnabled && $select.open">
From 2782103dbbe7083e1400edef642cc46b6fd50868 Mon Sep 17 00:00:00 2001 From: jverghese Date: Sun, 24 Aug 2014 23:54:29 -0700 Subject: [PATCH 3/3] Add tests for search enabled option. --- test/select.spec.js | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/select.spec.js b/test/select.spec.js index 1a6d09b7f..3897bbc8d 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -552,4 +552,66 @@ describe('ui-select tests', function() { }); + describe('search-enabled option', function() { + + var el; + + function setupSelectComponent(searchEnabled, theme) { + el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + } + + describe('selectize theme', function() { + + it('should show search input when true', function() { + setupSelectComponent('true', 'selectize'); + expect($(el).find('.ui-select-search')).not.toHaveClass('ng-hide'); + }); + + it('should hide search input when false', function() { + setupSelectComponent('false', 'selectize'); + expect($(el).find('.ui-select-search')).toHaveClass('ng-hide'); + }); + + }); + + describe('select2 theme', function() { + + it('should show search input when true', function() { + setupSelectComponent('true', 'select2'); + expect($(el).find('.select2-search')).not.toHaveClass('ng-hide'); + }); + + it('should hide search input when false', function() { + setupSelectComponent('false', 'select2'); + expect($(el).find('.select2-search')).toHaveClass('ng-hide'); + }); + + }); + + describe('bootstrap theme', function() { + + it('should show search input when true', function() { + setupSelectComponent('true', 'bootstrap'); + clickMatch(el); + expect($(el).find('.ui-select-search')).not.toHaveClass('ng-hide'); + }); + + it('should hide search input when false', function() { + setupSelectComponent('false', 'bootstrap'); + clickMatch(el); + expect($(el).find('.ui-select-search')).toHaveClass('ng-hide'); + }); + + }); + + }); + });