Reputation: 3622
It's about Rails and Formtastic.
How can I add a select box with formtastic without an initial/primary blank field? So that the initially selected item is the first item with content.
Upvotes: 27
Views: 10658
Reputation: 5038
Have you tried :include_blank => false
?
According to this (line 718) http://github.com/justinfrench/formtastic/blob/master/lib/formtastic.rb that should work.
Upvotes: 57
Reputation: 13424
You resolve this one of two ways:
First option: In each select box, specify if there should be a blank line or not. Options are:
<%= f.input :author, :as => :select, :include_blank => false %>
<%= f.input :author, :as => :select, :include_blank => true %>
<%= f.input :author, :as => :select, :include_blank => "No author" %>
The last version displays "No Author" as the display in the drop down, but submits the value as blank.
Second Option: Set the default in the config/initializers/formtastic.rb
.
# Should select fields have a blank option/prompt by default?
# Defaults to true.
Formtastic::FormBuilder.include_blank_for_select_by_default = false
By default, this is set to true
and all your drop downs will have blank options in them. Set it to false, and by default they all won't.
Upvotes: 24