最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add confirm: "Sure?" to f.submit - Stack Overflow

programmeradmin0浏览0评论

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?'

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?'
Share Improve this question edited May 23, 2017 at 11:47 CommunityBot 11 silver badge asked Jan 17, 2014 at 7:01 Fellow StrangerFellow Stranger 34.1k37 gold badges178 silver badges249 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

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?');
})
发布评论

评论列表(0)

  1. 暂无评论