This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 393393 if ( ctrl . taggingLabel === false ) {
394394 if ( ctrl . activeIndex < 0 ) {
395395 item = ctrl . tagging . fct !== undefined ? ctrl . tagging . fct ( ctrl . search ) : ctrl . search ;
396- if ( angular . equals ( ctrl . items [ 0 ] , item ) ) {
396+ if ( ! item || angular . equals ( ctrl . items [ 0 ] , item ) ) {
397397 return ;
398398 }
399399 } else {
412412 // use tagging function if we have one
413413 if ( ctrl . tagging . fct !== undefined && typeof item === 'string' ) {
414414 item = ctrl . tagging . fct ( ctrl . search ) ;
415+ if ( ! item ) return ;
415416 // if item type is 'string', apply the tagging label
416417 } else if ( typeof item === 'string' ) {
417418 // trim the trailing space
675676 if ( ctrl . tagging . fct ) {
676677 newItem = ctrl . tagging . fct ( newItem ) ;
677678 }
678- ctrl . select ( newItem , true ) ;
679+ if ( newItem ) ctrl . select ( newItem , true ) ;
679680 } ) ;
680681 }
681682 }
758759 if ( stashArr . filter ( function ( origItem ) { return angular . equals ( origItem , ctrl . tagging . fct ( ctrl . search ) ) ; } ) . length > 0 ) {
759760 return ;
760761 }
762+ newItem . isTag = true ;
761763 // handle newItem string and stripping dupes in tagging string context
762764 } else {
763765 // find any tagging items already in the ctrl.items array and store them
Original file line number Diff line number Diff line change @@ -317,6 +317,21 @@ describe('ui-select tests', function() {
317317 expect ( isDropdownOpened ( el3 ) ) . toEqual ( true ) ;
318318 } ) ;
319319
320+ it ( 'should allow decline tags when tagging function returns null' , function ( ) {
321+ scope . taggingFunc = function ( name ) {
322+ return null ;
323+ } ;
324+
325+ var el = createUiSelect ( { tagging : 'taggingFunc' } ) ;
326+ clickMatch ( el ) ;
327+
328+ $ ( el ) . scope ( ) . $select . search = 'idontexist' ;
329+ $ ( el ) . scope ( ) . $select . activeIndex = 0 ;
330+ $ ( el ) . scope ( ) . $select . select ( 'idontexist' ) ;
331+
332+ expect ( $ ( el ) . scope ( ) . $select . selected ) . not . toBeDefined ( ) ;
333+ } ) ;
334+
320335 it ( 'should allow tagging if the attribute says so' , function ( ) {
321336 var el = createUiSelect ( { tagging : true } ) ;
322337 clickMatch ( el ) ;
You can’t perform that action at this time.
0 commit comments