@@ -15,13 +15,7 @@ describe('ui-select tests', function () {
15
15
Escape : 27
16
16
} ;
17
17
18
- var multipleTagsTmpl =
19
- '<ui-select multiple tagging tagging-label="" ng-model="selection.selected"> \
20
- <ui-select-match ng-attr-placeholder="{{::placeholderText}}">{{$select.selected}}</ui-select-match> \
21
- <ui-select-choices repeat="item in items | filter: $select.search"> \
22
- <div ng-bind-html="item | highlight: $select.search"></div> \
23
- </ui-select-choices> \
24
- </ui-select>' ;
18
+ var defaultPlaceholder = 'Pick one...' ;
25
19
26
20
function isNil ( value ) {
27
21
return angular . isUndefined ( value ) || value === null ;
@@ -733,60 +727,6 @@ describe('ui-select tests', function () {
733
727
expect ( getMatchLabel ( el ) ) . toEqual ( 'false' ) ;
734
728
} ) ;
735
729
736
- it ( 'should not display the placeholder when tag is selected (by default)' , function ( ) {
737
- scope . items = [ 'tag1' , 'tag2' , 'tag3' ] ;
738
- scope . placeholderText = 'placeholder text' ;
739
-
740
- var el = compileTemplate ( multipleTagsTmpl ) ;
741
- var $select = el . scope ( ) . $select ; // uiSelectCtrl
742
-
743
- expect ( $select . selected ) . toEqual ( [ ] ) ;
744
- expect ( $select . getPlaceholder ( ) ) . toEqual ( scope . placeholderText ) ;
745
- expect ( getMatchPlaceholder ( el ) ) . toEqual ( scope . placeholderText ) ; // get placeholder
746
-
747
- clickItem ( el , 'tag1' ) ;
748
- expect ( $select . selected ) . toEqual ( [ 'tag1' ] ) ;
749
- expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ; // empty text
750
- expect ( getMatchPlaceholder ( el ) ) . toEqual ( '' ) ; // empty placeholder
751
-
752
- clickItem ( el , 'tag2' ) ;
753
- expect ( $select . selected ) . toEqual ( [ 'tag1' , 'tag2' ] ) ;
754
- expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
755
- expect ( getMatchPlaceholder ( el ) ) . toEqual ( '' ) ;
756
- } ) ;
757
-
758
- // Could be needed when e.g. tag is shown below the input
759
- it ( 'should display the placeholder when tag is selected (if user overrides .getPlaceholder())' , function ( ) {
760
- scope . items = [ 'tag1' , 'tag2' , 'tag3' ] ;
761
- scope . placeholderText = 'placeholder text' ;
762
-
763
- var el = compileTemplate ( multipleTagsTmpl ) ;
764
- var $select = el . scope ( ) . $select ;
765
-
766
- /**
767
- * In case user wants to show placeholder when the text is empty - they can override $select.getPlaceholder.
768
- * Cannot do this with $selectMultiple, bc <ui-select-multiple is appended inside the library
769
- * This override closes #1796
770
- */
771
- $select . getPlaceholder = function ( ) {
772
- return $select . placeholder ;
773
- } ;
774
-
775
- expect ( $select . selected ) . toEqual ( [ ] ) ;
776
- expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
777
- expect ( getMatchPlaceholder ( el ) ) . toEqual ( scope . placeholderText ) ;
778
-
779
- clickItem ( el , 'tag1' ) ;
780
- expect ( $select . selected ) . toEqual ( [ 'tag1' ] ) ;
781
- expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ; // empty text
782
- expect ( getMatchPlaceholder ( el ) ) . toEqual ( scope . placeholderText ) ; // show placeholder
783
-
784
- clickItem ( el , 'tag2' ) ;
785
- expect ( $select . selected ) . toEqual ( [ 'tag1' , 'tag2' ] ) ;
786
- expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
787
- expect ( getMatchPlaceholder ( el ) ) . toEqual ( scope . placeholderText ) ;
788
- } ) ;
789
-
790
730
it ( 'should close an opened select when another one is opened' , function ( ) {
791
731
var el1 = createUiSelect ( ) ;
792
732
var el2 = createUiSelect ( ) ;
@@ -1926,7 +1866,9 @@ describe('ui-select tests', function () {
1926
1866
function createUiSelectMultiple ( attrs ) {
1927
1867
var attrsHtml = '' ,
1928
1868
choicesAttrsHtml = '' ,
1929
- matchesAttrsHtml = '' ;
1869
+ matchesAttrsHtml = '' ,
1870
+ matchesPlaceholder = defaultPlaceholder ;
1871
+
1930
1872
if ( attrs !== undefined ) {
1931
1873
if ( attrs . disabled !== undefined ) { attrsHtml += ' ng-disabled="' + attrs . disabled + '"' ; }
1932
1874
if ( attrs . required !== undefined ) { attrsHtml += ' ng-required="' + attrs . required + '"' ; }
@@ -1936,23 +1878,27 @@ describe('ui-select tests', function () {
1936
1878
if ( attrs . taggingTokens !== undefined ) { attrsHtml += ' tagging-tokens="' + attrs . taggingTokens + '"' ; }
1937
1879
if ( attrs . taggingLabel !== undefined ) { attrsHtml += ' tagging-label="' + attrs . taggingLabel + '"' ; }
1938
1880
if ( attrs . inputId !== undefined ) { attrsHtml += ' input-id="' + attrs . inputId + '"' ; }
1939
- if ( attrs . groupBy !== undefined ) { choicesAttrsHtml += ' group-by="' + attrs . groupBy + '"' ; }
1940
- if ( attrs . uiDisableChoice !== undefined ) { choicesAttrsHtml += ' ui-disable-choice="' + attrs . uiDisableChoice + '"' ; }
1941
- if ( attrs . lockChoice !== undefined ) { matchesAttrsHtml += ' ui-lock-choice="' + attrs . lockChoice + '"' ; }
1942
1881
if ( attrs . removeSelected !== undefined ) { attrsHtml += ' remove-selected="' + attrs . removeSelected + '"' ; }
1943
1882
if ( attrs . resetSearchInput !== undefined ) { attrsHtml += ' reset-search-input="' + attrs . resetSearchInput + '"' ; }
1944
1883
if ( attrs . limit !== undefined ) { attrsHtml += ' limit="' + attrs . limit + '"' ; }
1945
1884
if ( attrs . onSelect !== undefined ) { attrsHtml += ' on-select="' + attrs . onSelect + '"' ; }
1946
1885
if ( attrs . removeSelected !== undefined ) { attrsHtml += ' remove-selected="' + attrs . removeSelected + '"' ; }
1947
- if ( attrs . refresh !== undefined ) { choicesAttrsHtml += ' refresh="' + attrs . refresh + '"' ; }
1948
- if ( attrs . refreshDelay !== undefined ) { choicesAttrsHtml += ' refresh-delay="' + attrs . refreshDelay + '"' ; }
1949
1886
if ( attrs . spinnerEnabled !== undefined ) { attrsHtml += ' spinner-enabled="' + attrs . spinnerEnabled + '"' ; }
1950
1887
if ( attrs . spinnerClass !== undefined ) { attrsHtml += ' spinner-class="' + attrs . spinnerClass + '"' ; }
1888
+
1889
+ if ( attrs . groupBy !== undefined ) { choicesAttrsHtml += ' group-by="' + attrs . groupBy + '"' ; }
1890
+ if ( attrs . uiDisableChoice !== undefined ) { choicesAttrsHtml += ' ui-disable-choice="' + attrs . uiDisableChoice + '"' ; }
1891
+ if ( attrs . refresh !== undefined ) { choicesAttrsHtml += ' refresh="' + attrs . refresh + '"' ; }
1892
+ if ( attrs . refreshDelay !== undefined ) { choicesAttrsHtml += ' refresh-delay="' + attrs . refreshDelay + '"' ; }
1893
+
1894
+ if ( attrs . lockChoice !== undefined ) { matchesAttrsHtml += ' ui-lock-choice="' + attrs . lockChoice + '"' ; }
1951
1895
}
1952
1896
1897
+ matchesAttrsHtml += ' placeholder="' + matchesPlaceholder + '"' ;
1898
+
1953
1899
return compileTemplate (
1954
1900
'<ui-select multiple ng-model="selection.selectedMultiple"' + attrsHtml + ' theme="bootstrap" style="width: 800px;"> \
1955
- <ui-select-match " ' + matchesAttrsHtml + ' placeholder="Pick one..." >{{$item.name}} <{{$item.email}}></ui-select-match> \
1901
+ <ui-select-match ' + matchesAttrsHtml + '>{{$item.name}} <{{$item.email}}></ui-select-match> \
1956
1902
<ui-select-choices repeat="person in people | filter: $select.search"' + choicesAttrsHtml + '> \
1957
1903
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1958
1904
<div ng-bind-html="person.email | highlight: $select.search"></div> \
@@ -3023,6 +2969,65 @@ describe('ui-select tests', function () {
3023
2969
triggerKeydown ( searchInput , Key . Enter ) ;
3024
2970
expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
3025
2971
} ) ;
2972
+
2973
+ it ( 'should not display the placeholder when tag is selected (by default)' , function ( ) {
2974
+ var placeholderText = defaultPlaceholder ;
2975
+
2976
+ var el = createUiSelectMultiple ( {
2977
+ tagging : '' ,
2978
+ taggingLabel : ''
2979
+ } ) ;
2980
+
2981
+ var $select = el . scope ( ) . $select ; // uiSelectCtrl
2982
+
2983
+ expect ( scope . selection . selectedMultiple ) . toBeUndefined ( ) ;
2984
+ expect ( $select . getPlaceholder ( ) ) . toEqual ( placeholderText ) ;
2985
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( placeholderText ) ; // get placeholder
2986
+
2987
+ clickItem ( el , scope . people [ 0 ] . name ) ;
2988
+ expect ( scope . selection . selectedMultiple ) . toEqual ( [ scope . people [ 0 ] ] ) ;
2989
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ; // empty text
2990
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( '' ) ; // empty placeholder
2991
+
2992
+ clickItem ( el , scope . people [ 1 ] . name ) ;
2993
+ expect ( scope . selection . selectedMultiple ) . toEqual ( [ scope . people [ 0 ] , scope . people [ 1 ] ] ) ;
2994
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
2995
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( '' ) ;
2996
+ } ) ;
2997
+
2998
+ // Could be needed when e.g. tag is shown below the input
2999
+ it ( 'should display the placeholder when tag is selected (if user overrides .getPlaceholder())' , function ( ) {
3000
+ var placeholderText = defaultPlaceholder ;
3001
+
3002
+ var el = createUiSelectMultiple ( {
3003
+ tagging : '' ,
3004
+ taggingLabel : ''
3005
+ } ) ;
3006
+ var $select = el . scope ( ) . $select ;
3007
+
3008
+ /**
3009
+ * In case user wants to show placeholder when the text is empty - they can override $select.getPlaceholder.
3010
+ * Cannot do this with $selectMultiple, bc <ui-select-multiple is appended inside the library
3011
+ * This override closes #1796
3012
+ */
3013
+ $select . getPlaceholder = function ( ) {
3014
+ return $select . placeholder ;
3015
+ } ;
3016
+
3017
+ expect ( $select . selected ) . toEqual ( [ ] ) ;
3018
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
3019
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( placeholderText ) ;
3020
+
3021
+ clickItem ( el , scope . people [ 0 ] . name ) ;
3022
+ expect ( $select . selected ) . toEqual ( [ scope . people [ 0 ] ] ) ;
3023
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ; // empty text
3024
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( placeholderText ) ; // show placeholder
3025
+
3026
+ clickItem ( el , scope . people [ 1 ] . name ) ;
3027
+ expect ( $select . selected ) . toEqual ( [ scope . people [ 0 ] , scope . people [ 1 ] ] ) ;
3028
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
3029
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( placeholderText ) ;
3030
+ } ) ;
3026
3031
} ) ;
3027
3032
3028
3033
describe ( 'resetSearchInput option multiple' , function ( ) {
0 commit comments