Abia Nasra
Abia Nasra

Reputation: 43

Disable Submit Button for 1 min after Submit in Rails

I am learning Rails, I have faced a problem. When I submit a form I get a pop up message to confirm. If I press Ok then form will submit and button will be Disable, its working.

But when I cancel popup confirmation then submit button also gets disabled when it should not.

I want to disable Submit button for 1min after submit the form and if I cancel popup confirmation, the submit button should activate.

Please help me to solve the problem.

<%= f.submit 'Submit', :class => "btn btn-yellow", data: { disable_with: "Please wait..." }%>

Upvotes: 1

Views: 1167

Answers (2)

webster
webster

Reputation: 4012

I guess date_disable_with will be best suited in this case since it disables the submit button until the form submission completed.

If you want to disable the submit button exactly for 1 minute, you need to use javascript for that.

For date_disable_with to work you need to include jquery and jquery-ujs in the page

Upvotes: 1

ksugiarto
ksugiarto

Reputation: 951

Have you try data_disabled_with? It will make the submit button disable automatically after first click, but will return to enabled if cancelled.

Check this RoR API

submit_tag
# => <input name="commit" data-disable-with="Save changes" type="submit" value="Save changes" />

submit_tag "Edit this article"
# => <input name="commit" data-disable-with="Edit this article" type="submit" value="Edit this article" />

submit_tag "Save edits", disabled: true
# => <input disabled="disabled" name="commit" data-disable-with="Save edits" type="submit" value="Save edits" />

submit_tag "Complete sale", data: { disable_with: "Submitting..." }
# => <input name="commit" data-disable-with="Submitting..." type="submit" value="Complete sale" />

submit_tag nil, class: "form_submit"
# => <input class="form_submit" name="commit" type="submit" />

submit_tag "Edit", class: "edit_button"
# => <input class="edit_button" data-disable-with="Edit" name="commit" type="submit" value="Edit" />

submit_tag "Save", data: { confirm: "Are you sure?" }
# => <input name='commit' type='submit' value='Save' data-disable-with="Save" data-confirm="Are you sure?" />

Upvotes: 0

Related Questions