Reputation: 7625
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]' %>
Upvotes: 35
Views: 51632
Reputation: 464
You can try this option:
<%= f.input :user, label: '[email protected]' %>
Upvotes: 1
Reputation: 1118
On rails 5.1 placeholder: 'aaaaaaaaaaa'
works. E.g.
<%= f.input :user, :placeholder => '[email protected]' %>
will work on rails 5.1
Upvotes: 2
Reputation: 922
You can simply do:
<% f.text_field, value: '[email protected]' %>
text_field
is good if you are working with form search gem like Ransack.
Upvotes: 12
Reputation: 1701
<%= f.input :user, :input_html => { :value => '[email protected]' } %>
Upvotes: 64
Reputation: 837
You can do this in the controller and keep data details out of your forms. Instead of this:
def new
@article = Article.new
end
you can do this:
def new
# hardcode default values (as shown) or generate on the fly
@article = Article.new(title: "10 Best Things")
end
The "new" form will open with the default (pre-set) values filled in. This should work with simple-form, plain old Rails, or any other form generator that does does things the Rails way..
Upvotes: 3