Rails:使用提交的表单中的数据形成确认消息 [英] Rails: Form confirm message with data from the submitted form
本文介绍了Rails:使用提交的表单中的数据形成确认消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图为从提交表单返回数据的rails表单确认一条消息 - 不仅仅是一个静态字符串。
<%form_for @foo do | f | - %GT;
<%f.text_field:number_of_bars - %>
<%f.submit:confirm =>你真的确定要使用## number_of_bars ##条吗? - %GT;
这个想法是,如果用户在数字栏中输入数字3,那么text字段中的确认信息会显示出这样的结果:你真的确定要使用3个小节吗?
任何想法如何做到这一点?
<试试这个:
<%= f.submit :onclick => return confirm('你确定要使用'+
document.getElementById('number_of_bars_id')。value +'?')%>
用您的id替换 number_of_bars_id
如果你有一点google,你可以找到一个方法来处理:confirm
。 p>
Trying to make a custom :confirm message for a rails form that returns data from the submitted form--not just a static string.
<% form_for @foo do |f| -%>
<% f.text_field :number_of_bars -%>
<% f.submit :confirm => Are you really sure you want to use ##number_of_bars## bars? -%>
The idea is if the user puts in the number 3 in the number of bars text field the confirm message would show up like this: "Are you really sure you want to use 3 bars?"
Any ideas how to do this?
解决方案
Try this:
<%= f.submit :onclick => "return confirm('Are you really sure you want to use '+
document.getElementById('number_of_bars_id').value + '?' )" %>
Replace the number_of_bars_id
with the id of your field.
If you google a bit you will find a way for this to work with :confirm
.
这篇关于Rails:使用提交的表单中的数据形成确认消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文