Use data-disabled-with on a non form submit button

1.9k views Asked by At

Rails provides data-disabled-with for button tags on form submits. Super awesome. However, link tags don't get this desired behavior. They're great to prevent users from clicking a button too many times and producing an unwarranted effect.

Is there a way I can do something like:

<a href="www.somewhere.com" data-disabled-with="Please Wait">Purchase me</a>
1

There are 1 answers

0
GOULETGOULET On

Rails provides this functionality via the :disable_with parameter of the link_to helper. See docs.

For example:

link_to("Create", create_post_path(@post), remote: true, disable_with: "Creating...")

Recognizing of course that creating a resource via a GET request isn't idiomatic Rails/REST... but this hopefully illustrates how it could be used.