Rails data-disable-with re-enabling button

前端 未结 4 1027
情深已故
情深已故 2021-01-31 03:32

I have a Rails Devise form that has javascript validation. When the user presses submit, the validation works and the user is refocused on the form where they need to be.

相关标签:
4条回答
  • 2021-01-31 03:57

    Look at my answer.

    $button = $('#someId')
    $.rails.enableElement($button)
    $button.removeAttr('disabled')
    

    https://stackoverflow.com/a/44318786/4349494

    0 讨论(0)
  • 2021-01-31 04:00

    I managed to solve this quite simply. I just went in and removed the data-disable-with from the button with the code:

        $('#my-button').removeAttr('data-disable-with');
    

    And then re-establishing the attribute when the form was ready to be submitted to prevent double clicks from creating duplicates.

    0 讨论(0)
  • 2021-01-31 04:14

    This behaviour was changed in Rails 5, now it's disabling submits by default.

    Rather than accepted answer, I would suggest to use the following configuration:

    config.action_view.automatically_disable_submit_tag = false
    

    or, to do it ad-hoc for specific buttons, add this to the submit button

    data: { disable_with: false }
    
    0 讨论(0)
  • 2021-01-31 04:14

    This was helpful to give me a hint on what to look for. If anyone is looking how to correct this in your html.erb file, this was my solution:

    <p>
      <%= f.submit 'Submit', data: { disable_with: false } %>
    </p>
    
    0 讨论(0)
提交回复
热议问题