This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree 2 files changed +19
-2
lines changed
2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 393
393
if ( ctrl . taggingLabel === false ) {
394
394
if ( ctrl . activeIndex < 0 ) {
395
395
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 ) ) {
397
397
return ;
398
398
}
399
399
} else {
412
412
// use tagging function if we have one
413
413
if ( ctrl . tagging . fct !== undefined && typeof item === 'string' ) {
414
414
item = ctrl . tagging . fct ( ctrl . search ) ;
415
+ if ( ! item ) return ;
415
416
// if item type is 'string', apply the tagging label
416
417
} else if ( typeof item === 'string' ) {
417
418
// trim the trailing space
675
676
if ( ctrl . tagging . fct ) {
676
677
newItem = ctrl . tagging . fct ( newItem ) ;
677
678
}
678
- ctrl . select ( newItem , true ) ;
679
+ if ( newItem ) ctrl . select ( newItem , true ) ;
679
680
} ) ;
680
681
}
681
682
}
758
759
if ( stashArr . filter ( function ( origItem ) { return angular . equals ( origItem , ctrl . tagging . fct ( ctrl . search ) ) ; } ) . length > 0 ) {
759
760
return ;
760
761
}
762
+ newItem . isTag = true ;
761
763
// handle newItem string and stripping dupes in tagging string context
762
764
} else {
763
765
// 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() {
317
317
expect ( isDropdownOpened ( el3 ) ) . toEqual ( true ) ;
318
318
} ) ;
319
319
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
+
320
335
it ( 'should allow tagging if the attribute says so' , function ( ) {
321
336
var el = createUiSelect ( { tagging : true } ) ;
322
337
clickMatch ( el ) ;
You can’t perform that action at this time.
0 commit comments