Skip to content


Always includes blank on select if use_required_attribute = true #997

diegocouto opened this Issue · 2 comments

2 participants


I can't remove the blank option from the select tags when use_required_attribute is being used. I tried to remove it locally:

<%= f.input :activity, as: :select, include_blank: false %>

and also changing the global configuration:

Formtastic::FormBuilder.include_blank_for_select_by_default = false

Unfortunately, none of these approaches worked as expected. The only whey to make it work is turning off the usage of the required attribute:

#Formtastic::FormBuilder.use_required_attribute = true


  • Rails 4.0.0
  • Formtastic 2.2.1

I'd love to help on this one, but we have specs that cover this and I'm having a hard time figuring out where this has gone wrong for you.

Here's the code path once we hit SelectInput:

      def to_html
        input_wrapping do
          hidden_input <<
          label_html <<
          (options[:group_by] ? grouped_select_html : select_html)

Assuming this is not a multi-select:

      def select_html, collection, input_options, input_html_options)
      def input_options
        super.merge :include_blank => (include_blank unless prompt?)

So, include_blank is where it gets interesting:

      def include_blank
        options.key?(:include_blank) ? options[:include_blank] : (single? && builder.include_blank_for_select_by_default)

If you have : include_blank => false and you haven't provided a :prompt in your input options, we pass :include_blank => false to (a standard Rails helper). I can't see anywhere that the use_required_attribute would impact this. I'm puzzled.

So, let's rule some stuff out:

  1. Is the view code you've show an exact copy-past from your view, or is there more to the puzzle?
  2. Is it a single select or a multi?
  3. Is this a new bug in old code, or a bug in new code?
  4. Are you using :prompt?
  5. Is there a bug in Rails' — can you get that to work? Was there a change to in Rails 4?
  6. Can you do a bundle open formtastic, edit SelectInput#select_html to inspect input_options?

Closing due to inactivity. Feel free to re-open with new information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.