@@ -15,6 +15,8 @@ describe('ui-select tests', function () {
15
15
Escape : 27
16
16
} ;
17
17
18
+ var defaultPlaceholder = 'Pick one...' ;
19
+
18
20
function isNil ( value ) {
19
21
return angular . isUndefined ( value ) || value === null ;
20
22
}
@@ -191,6 +193,10 @@ describe('ui-select tests', function () {
191
193
return $ ( el ) . find ( '.ui-select-match > span:first > span[ng-transclude]:not(.ng-hide)' ) . text ( ) ;
192
194
}
193
195
196
+ function getMatchPlaceholder ( el ) {
197
+ return el . find ( '.ui-select-search' ) . attr ( 'placeholder' )
198
+ }
199
+
194
200
function clickItem ( el , text ) {
195
201
196
202
if ( ! isDropdownOpened ( el ) ) {
@@ -1874,7 +1880,9 @@ describe('ui-select tests', function () {
1874
1880
function createUiSelectMultiple ( attrs ) {
1875
1881
var attrsHtml = '' ,
1876
1882
choicesAttrsHtml = '' ,
1877
- matchesAttrsHtml = '' ;
1883
+ matchesAttrsHtml = '' ,
1884
+ matchesPlaceholder = defaultPlaceholder ;
1885
+
1878
1886
if ( attrs !== undefined ) {
1879
1887
if ( attrs . disabled !== undefined ) { attrsHtml += ' ng-disabled="' + attrs . disabled + '"' ; }
1880
1888
if ( attrs . required !== undefined ) { attrsHtml += ' ng-required="' + attrs . required + '"' ; }
@@ -1884,23 +1892,27 @@ describe('ui-select tests', function () {
1884
1892
if ( attrs . taggingTokens !== undefined ) { attrsHtml += ' tagging-tokens="' + attrs . taggingTokens + '"' ; }
1885
1893
if ( attrs . taggingLabel !== undefined ) { attrsHtml += ' tagging-label="' + attrs . taggingLabel + '"' ; }
1886
1894
if ( attrs . inputId !== undefined ) { attrsHtml += ' input-id="' + attrs . inputId + '"' ; }
1887
- if ( attrs . groupBy !== undefined ) { choicesAttrsHtml += ' group-by="' + attrs . groupBy + '"' ; }
1888
- if ( attrs . uiDisableChoice !== undefined ) { choicesAttrsHtml += ' ui-disable-choice="' + attrs . uiDisableChoice + '"' ; }
1889
- if ( attrs . lockChoice !== undefined ) { matchesAttrsHtml += ' ui-lock-choice="' + attrs . lockChoice + '"' ; }
1890
1895
if ( attrs . removeSelected !== undefined ) { attrsHtml += ' remove-selected="' + attrs . removeSelected + '"' ; }
1891
1896
if ( attrs . resetSearchInput !== undefined ) { attrsHtml += ' reset-search-input="' + attrs . resetSearchInput + '"' ; }
1892
1897
if ( attrs . limit !== undefined ) { attrsHtml += ' limit="' + attrs . limit + '"' ; }
1893
1898
if ( attrs . onSelect !== undefined ) { attrsHtml += ' on-select="' + attrs . onSelect + '"' ; }
1894
1899
if ( attrs . removeSelected !== undefined ) { attrsHtml += ' remove-selected="' + attrs . removeSelected + '"' ; }
1895
- if ( attrs . refresh !== undefined ) { choicesAttrsHtml += ' refresh="' + attrs . refresh + '"' ; }
1896
- if ( attrs . refreshDelay !== undefined ) { choicesAttrsHtml += ' refresh-delay="' + attrs . refreshDelay + '"' ; }
1897
1900
if ( attrs . spinnerEnabled !== undefined ) { attrsHtml += ' spinner-enabled="' + attrs . spinnerEnabled + '"' ; }
1898
1901
if ( attrs . spinnerClass !== undefined ) { attrsHtml += ' spinner-class="' + attrs . spinnerClass + '"' ; }
1902
+
1903
+ if ( attrs . groupBy !== undefined ) { choicesAttrsHtml += ' group-by="' + attrs . groupBy + '"' ; }
1904
+ if ( attrs . uiDisableChoice !== undefined ) { choicesAttrsHtml += ' ui-disable-choice="' + attrs . uiDisableChoice + '"' ; }
1905
+ if ( attrs . refresh !== undefined ) { choicesAttrsHtml += ' refresh="' + attrs . refresh + '"' ; }
1906
+ if ( attrs . refreshDelay !== undefined ) { choicesAttrsHtml += ' refresh-delay="' + attrs . refreshDelay + '"' ; }
1907
+
1908
+ if ( attrs . lockChoice !== undefined ) { matchesAttrsHtml += ' ui-lock-choice="' + attrs . lockChoice + '"' ; }
1899
1909
}
1900
1910
1911
+ matchesAttrsHtml += ' placeholder="' + matchesPlaceholder + '"' ;
1912
+
1901
1913
return compileTemplate (
1902
1914
'<ui-select multiple ng-model="selection.selectedMultiple"' + attrsHtml + ' theme="bootstrap" style="width: 800px;"> \
1903
- <ui-select-match " ' + matchesAttrsHtml + ' placeholder="Pick one..." >{{$item.name}} <{{$item.email}}></ui-select-match> \
1915
+ <ui-select-match ' + matchesAttrsHtml + '>{{$item.name}} <{{$item.email}}></ui-select-match> \
1904
1916
<ui-select-choices repeat="person in people | filter: $select.search"' + choicesAttrsHtml + '> \
1905
1917
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1906
1918
<div ng-bind-html="person.email | highlight: $select.search"></div> \
@@ -2971,6 +2983,65 @@ describe('ui-select tests', function () {
2971
2983
triggerKeydown ( searchInput , Key . Enter ) ;
2972
2984
expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
2973
2985
} ) ;
2986
+
2987
+ it ( 'should not display the placeholder when tag is selected (by default)' , function ( ) {
2988
+ var placeholderText = defaultPlaceholder ;
2989
+
2990
+ var el = createUiSelectMultiple ( {
2991
+ tagging : '' ,
2992
+ taggingLabel : ''
2993
+ } ) ;
2994
+
2995
+ var $select = el . scope ( ) . $select ; // uiSelectCtrl
2996
+
2997
+ expect ( $select . selected ) . toEqual ( [ ] ) ;
2998
+ expect ( $select . getPlaceholder ( ) ) . toEqual ( placeholderText ) ;
2999
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( placeholderText ) ; // get placeholder
3000
+
3001
+ clickItem ( el , scope . people [ 0 ] . name ) ;
3002
+ expect ( $select . selected ) . toEqual ( [ scope . people [ 0 ] ] ) ;
3003
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ; // empty text
3004
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( '' ) ; // empty placeholder
3005
+
3006
+ clickItem ( el , scope . people [ 1 ] . name ) ;
3007
+ expect ( $select . selected ) . toEqual ( [ scope . people [ 0 ] , scope . people [ 1 ] ] ) ;
3008
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
3009
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( '' ) ;
3010
+ } ) ;
3011
+
3012
+ // Could be needed when e.g. tag is shown below the input
3013
+ it ( 'should display the placeholder when tag is selected (if user overrides .getPlaceholder())' , function ( ) {
3014
+ var placeholderText = defaultPlaceholder ;
3015
+
3016
+ var el = createUiSelectMultiple ( {
3017
+ tagging : '' ,
3018
+ taggingLabel : ''
3019
+ } ) ;
3020
+ var $select = el . scope ( ) . $select ;
3021
+
3022
+ /**
3023
+ * In case user wants to show placeholder when the text is empty - they can override $select.getPlaceholder.
3024
+ * Cannot do this with $selectMultiple, bc <ui-select-multiple is appended inside the library
3025
+ * This override closes #1796
3026
+ */
3027
+ $select . getPlaceholder = function ( ) {
3028
+ return $select . placeholder ;
3029
+ } ;
3030
+
3031
+ expect ( $select . selected ) . toEqual ( [ ] ) ;
3032
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
3033
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( placeholderText ) ;
3034
+
3035
+ clickItem ( el , scope . people [ 0 ] . name ) ;
3036
+ expect ( $select . selected ) . toEqual ( [ scope . people [ 0 ] ] ) ;
3037
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ; // empty text
3038
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( placeholderText ) ; // show placeholder
3039
+
3040
+ clickItem ( el , scope . people [ 1 ] . name ) ;
3041
+ expect ( $select . selected ) . toEqual ( [ scope . people [ 0 ] , scope . people [ 1 ] ] ) ;
3042
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
3043
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( placeholderText ) ;
3044
+ } ) ;
2974
3045
} ) ;
2975
3046
2976
3047
describe ( 'resetSearchInput option multiple' , function ( ) {
0 commit comments