From fae9b5ea4ad566fe58ae75b59dc436357911e78e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 10 Dec 2014 15:04:30 -0600 Subject: [PATCH 1/3] Added uiSelectFooter directive for bottom of list --- src/bootstrap/select.tpl.html | 1 + src/select.js | 18 +++++++++++++++++- src/select2/select.tpl.html | 1 + src/selectize/select.tpl.html | 1 + test/select.spec.js | 17 ++++++++++++++++- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/select.tpl.html b/src/bootstrap/select.tpl.html index 7ba6bd3d2..b51181486 100644 --- a/src/bootstrap/select.tpl.html +++ b/src/bootstrap/select.tpl.html @@ -6,4 +6,5 @@ ng-model="$select.search" ng-show="$select.searchEnabled && $select.open">
+ diff --git a/src/select.js b/src/select.js index 7f37d4296..73480a085 100644 --- a/src/select.js +++ b/src/select.js @@ -1169,12 +1169,28 @@ if (transcludedChoices.length !== 1) { throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length); } - element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); + element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); + + var transcludedFooter = transcluded.querySelectorAll('.ui-select-footer'); + transcludedFooter.removeAttr('ui-select-footer'); + if (transcludedFooter.length > 1) { + throw uiSelectMinErr('transcluded', "Expected 0 or 1 .ui-select-footer but got '{0}'.", transcludedFooter.length); + } + element.querySelectorAll('.ui-select-footer').replaceWith(transcludedFooter); }); } }; }]) + .directive('uiSelectFooter', function () { + return { + template: '', + restrict: 'EA', + transclude: true, + replace: true + }; + }) + .directive('uiSelectChoices', ['uiSelectConfig', 'RepeatParser', 'uiSelectMinErr', '$compile', function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { diff --git a/src/select2/select.tpl.html b/src/select2/select.tpl.html index d24bac66d..31cb794d2 100644 --- a/src/select2/select.tpl.html +++ b/src/select2/select.tpl.html @@ -12,5 +12,6 @@ ng-model="$select.search">
+ diff --git a/src/selectize/select.tpl.html b/src/selectize/select.tpl.html index 921e21618..4a6ca3c53 100644 --- a/src/selectize/select.tpl.html +++ b/src/selectize/select.tpl.html @@ -12,4 +12,5 @@ ng-disabled="$select.disabled">
+ diff --git a/test/select.spec.js b/test/select.spec.js index 6aab1b491..26d55fa25 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -78,6 +78,7 @@ describe('ui-select tests', function() {
\
\ \ + {{$select.items.length}} people \ ' ); } @@ -86,6 +87,10 @@ describe('ui-select tests', function() { return $(el).find('.ui-select-match > button:first > span[ng-transclude]:not(.ng-hide)').text(); } + function getFooter(el) { + return $(el).find('.ui-select-footer').text(); + } + function clickItem(el, text) { if (!isDropdownOpened(el)){ @@ -143,13 +148,23 @@ describe('ui-select tests', function() { expect(choicesContentEl.length).toEqual(1); var choicesContainerEl = $(el).find('.ui-select-choices'); - expect(choicesContainerEl.length).toEqual(1); + expect(choicesContainerEl.length).toEqual(1); + + var footerContainerEL = $(el).find('.ui-select-footer'); + expect(footerContainerEL.length).toEqual(1); openDropdown(el); var choicesEls = $(el).find('.ui-select-choices-row'); expect(choicesEls.length).toEqual(8); }); + it('should properly compile transcluded footer', function() { + var el = createUiSelect(); + openDropdown(el); + + expect(getFooter(el)).toEqual('8 people'); + }); + it('should correctly render initial state', function() { scope.selection.selected = scope.people[0]; From afa0c6a7e3e69d4ddbfe6f3fbe7d557531473d74 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 10 Dec 2014 15:16:44 -0600 Subject: [PATCH 2/3] Added example code to Select2 example --- examples/demo.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/demo.html b/examples/demo.html index dad80fc06..ac4918d34 100644 --- a/examples/demo.html +++ b/examples/demo.html @@ -77,7 +77,7 @@

Bootstrap theme

-

Select2 theme

+

Select2 theme (with optional footer)

Selected: {{person.selected}}

{{$select.selected.name}} @@ -88,6 +88,7 @@

Select2 theme

age: + {{$select.items.length}} people

Selectize theme

From a3107ba76e21f1bc49eaa5a3b03fc1c46bdd32c5 Mon Sep 17 00:00:00 2001 From: "csebold@gmail.com" Date: Fri, 11 Dec 2015 08:36:08 -0600 Subject: [PATCH 3/3] Updated to latest ui-select --- src/uiSelectDirective.js | 7 +++++++ src/uiSelectFooterDirective.js | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/uiSelectFooterDirective.js diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index ed3394d01..c592e4f12 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -192,6 +192,13 @@ uis.directive('uiSelect', throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length); } element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); + + var transcludedFooter = transcluded.querySelectorAll('.ui-select-footer'); + transcludedFooter.removeAttr('ui-select-footer'); + if (transcludedFooter.length > 1) { + throw uiSelectMinErr('transcluded', "Expected 0 or 1 .ui-select-footer but got '{0}'.", transcludedFooter.length); + } + element.querySelectorAll('.ui-select-footer').replaceWith(transcludedFooter); }); // Support for appending the select field to the body when its open diff --git a/src/uiSelectFooterDirective.js b/src/uiSelectFooterDirective.js new file mode 100644 index 000000000..687188c9f --- /dev/null +++ b/src/uiSelectFooterDirective.js @@ -0,0 +1,8 @@ +uis.directive('uiSelectFooter', function () { + return { + template: '', + restrict: 'EA', + transclude: true, + replace: true + }; +}); \ No newline at end of file