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

Commit 5f87457

Browse files
committed
Merge pull request #1011 from khanhto/master
feat(ui-select-no-choice): allow displaying information when there is no record found Adds a directive element for a no choice selection: <ui-select-no-choice> <div style="text-align: center;">There is nothing to show</div> </ui-select-no-choice>
2 parents 01a01da + fcd1eb4 commit 5f87457

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

src/bootstrap/no-choice.tpl.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<ul class="ui-select-no-choice dropdown-menu"
2+
ng-show="$select.items.length == 0">
3+
<li ng-transclude>
4+
5+
</li>
6+
</ul>

src/bootstrap/select.tpl.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
ng-model="$select.search"
1111
ng-show="$select.searchEnabled && $select.open">
1212
<div class="ui-select-choices"></div>
13+
<div class="ui-select-no-choice"></div>
1314
</div>

src/common.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ body > .select2-container.open {
153153
}
154154

155155
/* See Scrollable Menu with Bootstrap 3 http://stackoverflow.com/questions/19227496 */
156-
.ui-select-bootstrap > .ui-select-choices {
156+
.ui-select-bootstrap > .ui-select-choices ,.ui-select-bootstrap > .ui-select-no-choice {
157157
width: 100%;
158158
height: auto;
159159
max-height: 200px;

src/uiSelectDirective.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ uis.directive('uiSelect',
214214
throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length);
215215
}
216216
element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices);
217+
218+
var transcludedNoChoice = transcluded.querySelectorAll('.ui-select-no-choice');
219+
transcludedNoChoice.removeAttr('ui-select-no-choice'); //To avoid loop in case directive as attr
220+
transcludedNoChoice.removeAttr('data-ui-select-no-choice'); // Properly handle HTML5 data-attributes
221+
if (transcludedNoChoice.length == 1) {
222+
element.querySelectorAll('.ui-select-no-choice').replaceWith(transcludedNoChoice);
223+
}
217224
});
218225

219226
// Support for appending the select field to the body when its open

src/uiSelectNoChoiceDirective.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
uis.directive('uiSelectNoChoice',
2+
['uiSelectConfig', function (uiSelectConfig) {
3+
return {
4+
restrict: 'EA',
5+
require: '^uiSelect',
6+
replace: true,
7+
transclude: true,
8+
templateUrl: function (tElement) {
9+
// Gets theme attribute from parent (ui-select)
10+
var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
11+
return theme + '/no-choice.tpl.html';
12+
}
13+
};
14+
}]);

0 commit comments

Comments
 (0)