Commit 5f985711 authored by Phil Hughes's avatar Phil Hughes Committed by Alfredo Sumaran

Fixed enter submitting form in dropdown

Closes #19549
parent aba558a4
...@@ -24,33 +24,34 @@ class GitLabDropdownFilter ...@@ -24,33 +24,34 @@ class GitLabDropdownFilter
# Key events # Key events
timeout = "" timeout = ""
@input.on "keyup", (e) => @input
keyCode = e.which .on 'keydown', (e) ->
keyCode = e.which
return if ARROW_KEY_CODES.indexOf(keyCode) >= 0 e.preventDefault() if keyCode is 13
.on 'keyup', (e) =>
if @input.val() isnt "" and !$inputContainer.hasClass HAS_VALUE_CLASS keyCode = e.which
$inputContainer.addClass HAS_VALUE_CLASS
else if @input.val() is "" and $inputContainer.hasClass HAS_VALUE_CLASS return if ARROW_KEY_CODES.indexOf(keyCode) >= 0
$inputContainer.removeClass HAS_VALUE_CLASS
if @input.val() isnt '' and !$inputContainer.hasClass HAS_VALUE_CLASS
if keyCode is 13 $inputContainer.addClass HAS_VALUE_CLASS
return false else if @input.val() is '' and $inputContainer.hasClass HAS_VALUE_CLASS
$inputContainer.removeClass HAS_VALUE_CLASS
# Only filter asynchronously only if option remote is set
if @options.remote # Only filter asynchronously only if option remote is set
clearTimeout timeout if @options.remote
timeout = setTimeout => clearTimeout timeout
blur_field = @shouldBlur keyCode timeout = setTimeout =>
blur_field = @shouldBlur keyCode
if blur_field and @filterInputBlur
@input.blur() if blur_field and @filterInputBlur
@input.blur()
@options.query @input.val(), (data) =>
@options.callback(data) @options.query @input.val(), (data) =>
, 250 @options.callback(data)
else , 250
@filter @input.val() else
@filter @input.val()
shouldBlur: (keyCode) -> shouldBlur: (keyCode) ->
return BLUR_KEYCODES.indexOf(keyCode) >= 0 return BLUR_KEYCODES.indexOf(keyCode) >= 0
......
...@@ -87,5 +87,10 @@ class @Project ...@@ -87,5 +87,10 @@ class @Project
toggleLabel: (obj, $el) -> toggleLabel: (obj, $el) ->
$el.text().trim() $el.text().trim()
clicked: (e) -> clicked: (e) ->
$dropdown.closest('form').submit() if $('input[name="ref"]').length
$form = $dropdown.closest('form')
action = $form.attr('action')
divider = if action.indexOf('?') < 0 then '?' else '&'
Turbolinks.visit "#{action}#{divider}#{$form.serialize()}"
) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment