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.
Have you tried :include_blank => false
?
According to this (line 718) http://github.com/justinfrench/formtastic/blob/master/lib/formtastic.rb that should work.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With