44

I want to have a confirmation popup on a <% f.submit %> call on a new object form. Is there a way to do this without javascript?

1
  • 2
    POst your code, post your errors. What have you tried? Do you have any mockups or examples to show us what you want? (I'm trying to help you write a better question since you're new).
    – cbrulak
    Apr 2, 2013 at 18:39

2 Answers 2

81

You want <%= f.submit :confirm => 'Your confirm message' %>. Just FYI, this is just the short hand for the javascript call.

Edit: As stated in other answers, the new way to have a popup confirm is:

<%= f.submit 'Save', data: { confirm: 'Your confirm message' } %>
5
  • 4
    it should. Unless you have javascript turned off. If js is not enabled there is no way of doing what you want. If it is, you could try <%= f.submit :onclick => "return confirm('your message here')" %>
    – spullen
    Apr 2, 2013 at 18:40
  • <%= f.submit :onclick => "return confirm('your message here')" %> Works. I'm having a very difficult time understand the technology stack of the app I'm working on. Thanks.
    – Joe Essey
    Apr 2, 2013 at 19:22
  • But where does the button title go? I'm trying this, but it doesn't work: <%= f.submit "Some title", :confirm => 'Your confirm message' %> Jan 16, 2014 at 16:54
  • 4
    try <%= f.submit "title", data: { confirm: "confirm msg" } %>
    – Zernel
    Aug 27, 2014 at 3:19
  • 1
    The reasons those probably don't work (and onclick does) is because you are missing jquery/ujs. Jun 27, 2017 at 21:19
12

The correct way is to use:

= f.submit "Save", data: { confirm: "Are you sure you want to submit this form?" }

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.