Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 8218744

Browse files
committed
Extract into function to avoid duplicate code
1 parent 13aaff2 commit 8218744

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/uiSelectController.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ uis.controller('uiSelectCtrl',
373373
return isDisabled;
374374
};
375375

376+
function _replaceTaggingLabelAndTrim(item, taggingLabel) {
377+
return item.replace(taggingLabel, '').trim();
378+
}
376379

377380
// When the user selects an item with ENTER or clicks the dropdown
378381
ctrl.select = function(item, skipFocusser, $event) {
@@ -416,7 +419,7 @@ uis.controller('uiSelectCtrl',
416419
// if item type is 'string', apply the tagging label
417420
} else if ( typeof item === 'string' ) {
418421
// trim the trailing space
419-
item = item.replace(ctrl.taggingLabel,'').trim();
422+
item = _replaceTaggingLabelAndTrim(item, ctrl.taggingLabel);
420423
}
421424
}
422425
}
@@ -426,7 +429,7 @@ uis.controller('uiSelectCtrl',
426429
return;
427430
}
428431
} else if ( typeof item === 'string') {
429-
item = item.replace(ctrl.taggingLabel,'').trim();
432+
item = _replaceTaggingLabelAndTrim(item, ctrl.taggingLabel);
430433
}
431434
_resetSearchInput();
432435
$scope.$broadcast('uis:select', item);

0 commit comments

Comments
 (0)