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

Commit

Permalink
New feature: Allow displaying information when there is no record found.
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhto committed Mar 25, 2016
1 parent 2d1422d commit fcd1eb4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/bootstrap/no-choice.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ul class="ui-select-no-choice dropdown-menu"
ng-show="$select.items.length == 0">
<li ng-transclude>

</li>
</ul>
1 change: 1 addition & 0 deletions src/bootstrap/select.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
ng-model="$select.search"
ng-show="$select.searchEnabled && $select.open">
<div class="ui-select-choices"></div>
<div class="ui-select-no-choice"></div>
</div>
2 changes: 1 addition & 1 deletion src/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ body > .select2-container.open {
}

/* See Scrollable Menu with Bootstrap 3 http://stackoverflow.com/questions/19227496 */
.ui-select-bootstrap > .ui-select-choices {
.ui-select-bootstrap > .ui-select-choices ,.ui-select-bootstrap > .ui-select-no-choice {
width: 100%;
height: auto;
max-height: 200px;
Expand Down
7 changes: 7 additions & 0 deletions src/uiSelectDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,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 transcludedNoChoice = transcluded.querySelectorAll('.ui-select-no-choice');
transcludedNoChoice.removeAttr('ui-select-no-choice'); //To avoid loop in case directive as attr
transcludedNoChoice.removeAttr('data-ui-select-no-choice'); // Properly handle HTML5 data-attributes
if (transcludedNoChoice.length == 1) {
element.querySelectorAll('.ui-select-no-choice').replaceWith(transcludedNoChoice);
}
});

// Support for appending the select field to the body when its open
Expand Down
14 changes: 14 additions & 0 deletions src/uiSelectNoChoiceDirective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uis.directive('uiSelectNoChoice',
['uiSelectConfig', function (uiSelectConfig) {
return {
restrict: 'EA',
require: '^uiSelect',
replace: true,
transclude: true,
templateUrl: function (tElement) {
// Gets theme attribute from parent (ui-select)
var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
return theme + '/no-choice.tpl.html';
}
};
}]);

0 comments on commit fcd1eb4

Please sign in to comment.