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

Commit

Permalink
Merge pull request #1011 from khanhto/master
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aaronroberson committed Mar 28, 2016
2 parents 01a01da + fcd1eb4 commit 5f87457
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 @@ -153,7 +153,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 @@ -214,6 +214,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 5f87457

Please sign in to comment.