简体   繁体   中英

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!!

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?

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'

$('.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' %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM