Can't find an answer anywhere in Docs... is there a way to make it so that the placeholder value for a number_field_tag
or whatever is the value that is submitted to the value
if the user doesn't enter anything else?
I.e., in my code below:
<%= number_field_tag "transaction[][#{thing}]", :quantity, min: 0, placeholder: @transactionparams ? @transactionparams["#{thing}"] : 0 %>
I would like the equation in placeholder to evaluate and then be POSTed if the user doesn't enter anything else.
Thanks!
HTML
The issue is HTML, not Rails
The problem is a placeholder is only there to give text that's visible only when the input has no value:
The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format).
The short hint is displayed in the input field before the user enters a value.
This attribute (placeholder) does not store any data in the input, meaning when you submit the form, it's not going to send anything to your backend. To fix this, you should should switch from using the placeholder
to value
attribute:
<%= number_field_tag "transaction[][#{thing}]", :quantity, min: 0, value: @transactionparams ? @transactionparams["#{thing}"] : 0 %>