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

Commit fcd1eb4

Browse files
committed
New feature: Allow displaying information when there is no record found.
1 parent 2d1422d commit fcd1eb4

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
@@ -148,7 +148,7 @@ body > .select2-container.open {
148148
}
149149

150150
/* See Scrollable Menu with Bootstrap 3 http://stackoverflow.com/questions/19227496 */
151-
.ui-select-bootstrap > .ui-select-choices {
151+
.ui-select-bootstrap > .ui-select-choices ,.ui-select-bootstrap > .ui-select-no-choice {
152152
width: 100%;
153153
height: auto;
154154
max-height: 200px;

src/uiSelectDirective.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ uis.directive('uiSelect',
186186
throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length);
187187
}
188188
element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices);
189+
190+
var transcludedNoChoice = transcluded.querySelectorAll('.ui-select-no-choice');
191+
transcludedNoChoice.removeAttr('ui-select-no-choice'); //To avoid loop in case directive as attr
192+
transcludedNoChoice.removeAttr('data-ui-select-no-choice'); // Properly handle HTML5 data-attributes
193+
if (transcludedNoChoice.length == 1) {
194+
element.querySelectorAll('.ui-select-no-choice').replaceWith(transcludedNoChoice);
195+
}
189196
});
190197

191198
// 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)