Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails number_field tag placeholder?

Hi I have a number_field tag as follow:

<%= number_field :average_border, nil, min: 1, max: 4, :step => 'any', class: "number" %>

This number_filed tag is meant to be updated as pleased by the user with a number from 1 to 4.

I would like this tag to display the current value as a placeholder would do in a text field tag.

Thanks !

like image 485
Antoine Avatar asked Dec 24 '22 20:12

Antoine


1 Answers

You can pass placeholder attribute into it. But make sure you use the correct form helpers

if you are using form_tag

<%= number_field_tag :average_border, @current_value, min: 1, max: 4, :step => 'any', class: "number", placeholder: @hint_value %>

if you are using form_for

<%= f.number_field :average_border, min: 1, max: 4, :step => 'any', class: "number", placeholder: hint_value %>
like image 52
mininoz Avatar answered Jan 07 '23 04:01

mininoz