From 69ebe8e3487639c5f7f25835b6e4b3420f67b3e3 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 19 Jun 2015 17:31:37 +0200 Subject: [PATCH] - prevent submit when selecting value with enter key - prevent tabbing in next element if select options are shown --- .../lib/app_post/searchable_select.js.coffee | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/searchable_select.js.coffee b/app/assets/javascripts/app/lib/app_post/searchable_select.js.coffee index eb5a8b762..97731cc8a 100644 --- a/app/assets/javascripts/app/lib/app_post/searchable_select.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/searchable_select.js.coffee @@ -52,8 +52,9 @@ class App.SearchableSelect extends Spine.Controller switch event.keyCode when 40 then @nudge event, 1 # down when 38 then @nudge event, -1 # up - when 13 then @selectHighlightedItem() # enter + when 13 then @onEnter event when 27 then @onEscape() + when 9 then @onTab event onEscape: -> @toggle() if @isOpen @@ -78,9 +79,18 @@ class App.SearchableSelect extends Spine.Controller @input.val event.currentTarget.textContent.trim() @shadowInput.val event.currentTarget.getAttribute('data-value') - selectHighlightedItem: -> + onTab: (event) -> + return if not @isOpen + event.preventDefault() + + onEnter: (event) -> if not @isOpen - return @toggle() + if @shadowInput.val() is '' + event.preventDefault() + @toggle() + return + + event.preventDefault() @input.val @values.filter('.is-active').text().trim() @shadowInput.val @values.filter('.is-active').attr('data-value') @@ -88,7 +98,7 @@ class App.SearchableSelect extends Spine.Controller filterList: (event) => @toggle() if not @isOpen - + query = @input.val() @filterByQuery query