bft
bft

Reputation: 35

rails simple_form submit button with confirm

I'm working in Rails 4 using simple_form and using wicked to create a wizard.

I have a button that works great:

<%= f.button :button, "<i class='fa fa-chevron-right btn-next'></i>".html_safe, data: {disable_with: "<i class='fa fa-spinner fa-spin fa-2x'></i>"} %>

But for one of the steps I'd like to add a popup like this (which also works):

<%= f.submit :button, data: {confirm: "Are you sure this information is correct?"} %>

However, I can't figure out how to get them both together, something like this:

<%= f.button :button, "<i class='fa fa-chevron-right btn-next'></i>".html_safe, data: { confirm: "Are you sure this information is correct?", disable_with: "<i class='fa fa-spinner fa-spin fa-2x'></i>"} %>

This ends up doing 2 popups and then doesn't submit anything and stays on the same page.

Any ideas? Thanks!!

Upvotes: 1

Views: 4355

Answers (3)

bft
bft

Reputation: 35

So it turns out this was a problem with the jquery-rails gem.

https://github.com/rails/jquery-rails/issues/173

In my gem file, I changed from this: gem 'jquery-rails'

To this: gem 'jquery-rails', '~> 3.0'

Upvotes: 0

Vrushali Pawar
Vrushali Pawar

Reputation: 3803

$('.submit-button').on("click", function() {
    if (confirm('Are you sure ?')) {
        $(".form-vertical").submit();
    }
})

<%= f.button :button, "<i class='fa fa-chevron-right btn-next'></i>".html_safe, data: {disable_with: "<i class='fa fa-spinner fa-spin fa-2x'></i>"}, class: 'submit-button' %>

Upvotes: 0

Meri Alvarado
Meri Alvarado

Reputation: 191

It seems to work when I substitute your code for the button on my existing simple_form code. Hmm can you post the code for the simple_form?

Upvotes: 0

Related Questions