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

Commit f672837

Browse files
committed
Merge pull request #287 from angular-ui/feat-allowclear
Show x icon to clear/reset the current value (like select2)
2 parents f8c2ec7 + d6d1669 commit f672837

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

src/select.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@
973973
attrs.$observe('placeholder', function(placeholder) {
974974
$select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder;
975975
});
976+
977+
$select.allowClear = (angular.isDefined(attrs.allowClear)) ? (attrs.allowClear === '') ? true : (attrs.allowClear.toLowerCase() === 'true') : false;
976978

977979
if($select.multiple){
978980
$select.sizeSearchInput();

src/select2/match.tpl.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
ng-click="$select.activate()">
99
<span ng-show="$select.isEmpty()" class="select2-chosen">{{$select.placeholder}}</span>
1010
<span ng-hide="$select.isEmpty()" class="select2-chosen" ng-transclude></span>
11+
<abbr ng-if="$select.allowClear && !$select.isEmpty()" class="select2-search-choice-close" ng-click="$select.select(undefined)"></abbr>
1112
<span class="select2-arrow ui-select-toggle" ng-click="$select.toggle($event)"><b></b></span>
1213
</a>

src/select2/select.tpl.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<div class="select2 select2-container"
22
ng-class="{'select2-container-active select2-dropdown-open': $select.open,
33
'select2-container-disabled': $select.disabled,
4-
'select2-container-active': $select.focus }">
4+
'select2-container-active': $select.focus,
5+
'select2-allowclear': $select.allowClear && !$select.isEmpty()}">
56
<div class="ui-select-match"></div>
67
<div class="select2-drop select2-with-searchbox select2-drop-active"
78
ng-class="{'select2-display-none': !$select.open}">

0 commit comments

Comments
 (0)