@@ -15,13 +15,7 @@ describe('ui-select tests', function () {
1515 Escape : 27
1616 } ;
1717
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...' ;
2519
2620 function isNil ( value ) {
2721 return angular . isUndefined ( value ) || value === null ;
@@ -733,60 +727,6 @@ describe('ui-select tests', function () {
733727 expect ( getMatchLabel ( el ) ) . toEqual ( 'false' ) ;
734728 } ) ;
735729
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-
790730 it ( 'should close an opened select when another one is opened' , function ( ) {
791731 var el1 = createUiSelect ( ) ;
792732 var el2 = createUiSelect ( ) ;
@@ -1926,7 +1866,9 @@ describe('ui-select tests', function () {
19261866 function createUiSelectMultiple ( attrs ) {
19271867 var attrsHtml = '' ,
19281868 choicesAttrsHtml = '' ,
1929- matchesAttrsHtml = '' ;
1869+ matchesAttrsHtml = '' ,
1870+ matchesPlaceholder = defaultPlaceholder ;
1871+
19301872 if ( attrs !== undefined ) {
19311873 if ( attrs . disabled !== undefined ) { attrsHtml += ' ng-disabled="' + attrs . disabled + '"' ; }
19321874 if ( attrs . required !== undefined ) { attrsHtml += ' ng-required="' + attrs . required + '"' ; }
@@ -1936,23 +1878,27 @@ describe('ui-select tests', function () {
19361878 if ( attrs . taggingTokens !== undefined ) { attrsHtml += ' tagging-tokens="' + attrs . taggingTokens + '"' ; }
19371879 if ( attrs . taggingLabel !== undefined ) { attrsHtml += ' tagging-label="' + attrs . taggingLabel + '"' ; }
19381880 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 + '"' ; }
19421881 if ( attrs . removeSelected !== undefined ) { attrsHtml += ' remove-selected="' + attrs . removeSelected + '"' ; }
19431882 if ( attrs . resetSearchInput !== undefined ) { attrsHtml += ' reset-search-input="' + attrs . resetSearchInput + '"' ; }
19441883 if ( attrs . limit !== undefined ) { attrsHtml += ' limit="' + attrs . limit + '"' ; }
19451884 if ( attrs . onSelect !== undefined ) { attrsHtml += ' on-select="' + attrs . onSelect + '"' ; }
19461885 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 + '"' ; }
19491886 if ( attrs . spinnerEnabled !== undefined ) { attrsHtml += ' spinner-enabled="' + attrs . spinnerEnabled + '"' ; }
19501887 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 + '"' ; }
19511895 }
19521896
1897+ matchesAttrsHtml += ' placeholder="' + matchesPlaceholder + '"' ;
1898+
19531899 return compileTemplate (
19541900 '<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> \
19561902 <ui-select-choices repeat="person in people | filter: $select.search"' + choicesAttrsHtml + '> \
19571903 <div ng-bind-html="person.name | highlight: $select.search"></div> \
19581904 <div ng-bind-html="person.email | highlight: $select.search"></div> \
@@ -3023,6 +2969,65 @@ describe('ui-select tests', function () {
30232969 triggerKeydown ( searchInput , Key . Enter ) ;
30242970 expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
30252971 } ) ;
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 ( $select . selected ) . toEqual ( [ ] ) ;
2984+ expect ( $select . getPlaceholder ( ) ) . toEqual ( placeholderText ) ;
2985+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( placeholderText ) ; // get placeholder
2986+
2987+ clickItem ( el , scope . people [ 0 ] . name ) ;
2988+ expect ( $select . selected ) . 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 ( $select . selected ) . 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+ } ) ;
30263031 } ) ;
30273032
30283033 describe ( 'resetSearchInput option multiple' , function ( ) {
0 commit comments