Skip to content

Commit

Permalink
add turboboost-form-processing class for active form ajax requests
Browse files Browse the repository at this point in the history
connect to #20
  • Loading branch information
waymondo committed Jan 20, 2017
1 parent 010e326 commit 0986134
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/assets/javascripts/turboboost/turboboost.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ turboboostable = "[data-turboboost]"
errID = "#error_explanation"
errTemplate = (errors) ->
"<ul><li>#{$.makeArray(errors).join('</li><li>')}</li></ul>"
formProcessingClass = 'turboboost-form-processing'

enableForm = ($form) ->
$form.removeClass(formProcessingClass)
$form.find("[type='submit']").removeAttr('disabled').data('turboboostDisabled', false)

disableForm = ($form) ->
$form.addClass(formProcessingClass)
$form.find("[type='submit']").attr('disabled', 'disabled').data('turboboostDisabled', true)

tryJSONParse = (str) ->
Expand Down Expand Up @@ -73,7 +76,7 @@ turboboostBeforeSend = (e, xhr, settings) ->
isForm = @nodeName is "FORM"
return e.stopPropagation() unless isForm
$el = $(@)
disableForm $el if Turboboost.handleFormDisabling
disableForm $el if isForm and Turboboost.handleFormDisabling
if settings.type is "GET" and !$el.attr('data-no-turboboost-redirect')
Turbolinks.visit [@action, $el.serialize()].join("?")
return false
Expand Down Expand Up @@ -102,7 +105,7 @@ maybeInsertSuccessResponseBody = (resp) ->

maybeReenableForms = ->
return unless Turboboost.handleFormDisabling
$("form#{turboboostable} input[type='submit']").each ->
$("form#{turboboostable} [type='submit']").each ->
enableForm $(@).closest('form') if $(@).data('turboboostDisabled')

$(document)
Expand Down

0 comments on commit 0986134

Please sign in to comment.