I have this piece of code:
= f.input :category, :as => :select, :label => false, :collection => Choices["Categories"]
Choices["Categories"] is just a hash of key=>value pairs.
SimpleForm generates a select field with all needed options, but it also makes the first option blank.
This blank option is present in all select fields that were generated by SimpleForm.
But I don't want to have a blank option. Is there a way to get rid of it?
Something like :allow_blank_option => false
?
I tried to make a presence validation of this attribute hoping that SimpleForm will detect it, but it didn't help.
You can pass a include_blank: false, include_hidden: false
option:
= f.input :category, :as => :select, :label => false, :collection => Choices["Categories"], include_blank: false, include_hidden: false
or you can customize call back action in your model to remove any empty string in the array parameter, assuming a parameter with the name "types":
before_validation :remove_empty_string def remove_empty_string types.reject! { |l| l.empty? } end
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