Ruby-on-rails Rails - 如何在 f.submit 上放置确认弹出窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15771582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:44:04  来源:igfitidea点击:

Rails - How to put a confirmation popup on a f.submit?

ruby-on-rails

提问by Joe Essey

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?

我想在<% f.submit %>调用新对象表单时弹出确认窗口。有没有办法在没有 javascript 的情况下做到这一点?

回答by spullen

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

你要<%= f.submit :confirm => 'Your confirm message' %>。仅供参考,这只是 javascript 调用的简写。

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

编辑:如其他答案所述,弹出确认的新方法是:

<%= f.submit 'Save', data: { confirm: 'Your confirm message' } %>

回答by Teej

The correct way is to use:

正确的方法是使用:

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