Mr. Sinko
Mr. Sinko

Reputation: 91

`disable_with` to prevent double clicks

I am trying to add a disable_with to one of my button, however I can't get the correct syntax. Here's what I have tried so far.

before adding disable_with //this one work before however I can click cancel button multiple times

- content_for :cancel_button do
    #{cancel_shift_path(@shift)}

After adding disable_with //incorrect syntax

- content_for :cancel_button do
    #{cancel_shift_path(@shift), data: {disable_with: "Please wait"}}

Upvotes: 1

Views: 176

Answers (1)

What you need to use is the button_tag helper:

<% content_for :cancel_button do %>
  <%= button_tag "#{cancel_shift_path(@shift)", data: { disable_with: "Please wait..."} %>
<% end %>

Here is the api reference: https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-button_tag

Upvotes: 1

Related Questions