Rails: form confirmation message with data from the submitted form

Attempt to make an order: to confirm the message for the rails form, which returns data from the submitted form, and 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 that the user enters number 3 in the column text box, a confirmation message will be displayed as follows: "Are you really sure you want to use 3 bars?"

Any ideas how to do this?

+4
source share
1 answer

Try the following:

 <%= f.submit :onclick => "return confirm('Are you really sure you want to use '+ document.getElementById('number_of_bars_id').value + '?' )" %> 

Replace number_of_bars_id with your field id.

If you share a little Google, you will find a way to work with :confirm .

+5
source

Source: https://habr.com/ru/post/1302922/


All Articles