From 11bd40d04bed6c2f6d7be2bf9e783f6495e728cd Mon Sep 17 00:00:00 2001 From: Deimos Date: Fri, 26 Apr 2019 00:32:02 -0600 Subject: [PATCH] Fix empty tag field behavior when backspacing If there were no tag chips, backspacing on the empty field would lose focus (and on some browsers, another backspace would then go back). --- tildes/static/js/behaviors/autocomplete-input.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tildes/static/js/behaviors/autocomplete-input.js b/tildes/static/js/behaviors/autocomplete-input.js index 3413d36..0549bef 100644 --- a/tildes/static/js/behaviors/autocomplete-input.js +++ b/tildes/static/js/behaviors/autocomplete-input.js @@ -105,10 +105,12 @@ $.onmount('[data-js-autocomplete-input]', function() { var $tagsHiddenInput = $("[data-js-autocomplete-hidden-input]"); var $lastChip = $chips.children().last(); - $(this).blur(); - if (!$lastChip.hasClass('active')) { - $lastChip.addClass("active"); - $lastChip.children('[data-js-autocomplete-chip-clear]').first().focus(); + if ($lastChip.length) { + $(this).blur(); + if (!$lastChip.hasClass('active')) { + $lastChip.addClass("active"); + $lastChip.children('[data-js-autocomplete-chip-clear]').first().focus(); + } } } break;