Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add confirm: "Sure?" to f.submit

I have a form with a submit_tag.

I want both to set the content value and have a js popup confirming the intent.

I've tried the suggestion in this answer and what the docs describe.

Neither of the below invoke the confirmation dialog, but it does for a link_to tag. What am I doing wrong?

f.submit "Do this", data: {confirm: 'Are you sure?'}  
f.submit "Do this", confirm: 'Are you sure?'
f.submit confirm: 'Are you sure?'
like image 691
Fellow Stranger Avatar asked Jan 17 '14 07:01

Fellow Stranger


1 Answers

Add this onsubmit function to your form helper

<%= form_for(...  , html: {:onsubmit => "return confirm('Are you sure?');" }) do |f| %>

If you have jQuery and want to do it un-obstructively, you can do inside of document ready

$('#my-form').submit(function() {
  return confirm('Are you sure?');
})
like image 77
Santhosh Avatar answered Oct 19 '22 19:10

Santhosh