Rails:使用提交的表單中的數據確認消息

[英]Rails: Form confirm message with data from the submitted form


Trying to make a custom :confirm message for a rails form that returns data from the submitted form--not just a static string.

嘗試創建自定義:確認從提交的表單返回數據的rails表單的消息 - 而不僅僅是靜態字符串。

<% 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?"

這個想法是,如果用戶在條形文本字段中輸入數字3,則確認消息將顯示如下:“你真的確定要使用3個條形碼嗎?”

Any ideas how to do this?

任何想法如何做到這一點?

1 个解决方案

#1


5  

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.

將number_of_bars_id替換為您的字段的ID。

If you google a bit you will find a way for this to work with :confirm.

如果你稍微谷歌,你會發現一種方法可以使用:確認。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/03/02/720c793dd78ef9180095f1ee2b5c5fa0.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com