From ef282e187b221981d11f025bc075ab8cc2b0744d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 21 Jun 2017 08:59:51 +0200 Subject: [PATCH] Improved tree select feature - allow also to select node/parent of childs. --- .../app/lib/app_post/searchable_select.coffee | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/searchable_select.coffee b/app/assets/javascripts/app/lib/app_post/searchable_select.coffee index 010bbddcf..ce1e3713e 100644 --- a/app/assets/javascripts/app/lib/app_post/searchable_select.coffee +++ b/app/assets/javascripts/app/lib/app_post/searchable_select.coffee @@ -215,6 +215,7 @@ class App.SearchableSelect extends Spine.Controller @invisiblePart.text('') selectItem: (event) -> + return if !event.currentTarget.textContent @input.val event.currentTarget.textContent.trim() @input.trigger('change') @shadowInput.val event.currentTarget.getAttribute('data-value') @@ -222,6 +223,7 @@ class App.SearchableSelect extends Spine.Controller navigateIn: (event) -> event.stopPropagation() + @selectItem(event) @navigateDepth(1) navigateOut: (event) -> @@ -305,9 +307,7 @@ class App.SearchableSelect extends Spine.Controller onEnter: (event) -> if @currentItem - if @currentItem.hasClass('js-enter') - return @navigateIn(event) - else if @currentItem.hasClass('js-back') + if @currentItem.hasClass('js-back') return @navigateOut(event) @clearAutocomplete() @@ -326,10 +326,16 @@ class App.SearchableSelect extends Spine.Controller @input.val valueName @shadowInput.val value - @currentItem = null - @input.trigger('change') @shadowInput.trigger('change') + + if @currentItem + if @currentItem.hasClass('js-enter') + @navigateIn(event) + @currentItem = null + return + @currentItem = null + @toggle() onBlur: ->