Adding a default value to text-input in simple-form
45,190
Solution 1
<%= f.input :user, :input_html => { :value => '[email protected]' } %>
Solution 2
You can simply do:
<% f.text_field, value: '[email protected]' %>
text_field
is good if you are working with form search gem like Ransack.
Solution 3
On rails 5.1 placeholder: 'aaaaaaaaaaa'
works. E.g.
<%= f.input :user, :placeholder => '[email protected]' %>
will work on rails 5.1
Author by
Mark
Updated on December 04, 2020Comments
-
Mark over 3 years
I want to add a default value to a text-input field using simple-form. With
:placeholder
it is not used as default....<%= f.input :user, :placeholder => '[email protected]' %>
-
mmike almost 8 yearsto have default value and also keep actual value in field (for example user's email) try like this --- f.input :user, input_html: { value: @user.email.present? ? @user.email : '[email protected]' }. Also its new more readable syntax in RoR
-
-
Sergey Kishenin almost 12 yearsMaybe,
:input_html => { :value => '[email protected]' }
-
pgrosslicht almost 12 yearsYes, realized that too. Fixed it.
-
Gareth Jones over 10 yearsI think if you do not use the :input_html option and simply use :value or value: then that value will be reset to the default each time you return to the edit page.