From 168424a0350d59df2710a39ca990d78ff1511395 Mon Sep 17 00:00:00 2001 From: Anton Ignatov Date: Tue, 7 May 2019 14:47:44 +0200 Subject: [PATCH] Add tag on enter button --- app/assets/javascripts/select2_customization.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/select2_customization.js b/app/assets/javascripts/select2_customization.js index 2605e7f59..4ce47deca 100644 --- a/app/assets/javascripts/select2_customization.js +++ b/app/assets/javascripts/select2_customization.js @@ -145,12 +145,15 @@ $.fn.extend({ $('.select2').find('input, .select2-selection__rendered').off('keydown').on('keydown', function(e) { var activeElement = $('.select2-results .arrow_pointer'); + var firstElement = $('.select2-results .select2-results__option').first(); var groupElement = activeElement.find('.select2-results__group'); if (e.keyCode === 13) { if (groupElement.length > 0) { groupElement.click(); - } else { + } else if (activeElement.length > 0) { activeElement.mouseup(); + } else { + firstElement.mouseup(); } setTimeout(() => {