From 9f0d694f0a5b39668ea36005d96acd7a2d01f7d1 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Wed, 25 Mar 2020 06:51:39 +0100 Subject: [PATCH] Prevent angular crash when adding already existing tag --- src/js/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/js/index.js b/src/js/index.js index 13974ae38..9073feea5 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -595,11 +595,13 @@ app.directive('tagInput', function () { }); }; $scope.addTag = function () { - var tagArray; - if ($scope.tagText.length === 0) { - return; + var tagArray = $scope.tagArray(); + + // prevent adding empty or existing items + if ($scope.tagText.length === 0 || tagArray.indexOf($scope.tagText) !== -1) { + return $scope.tagText = ''; } - tagArray = $scope.tagArray(); + tagArray.push($scope.tagText); $scope.inputTags = tagArray.join(','); return $scope.tagText = '';