开发者

Formtastic - customise blank option in select tag

开发者 https://www.devze.com 2023-02-05 00:00 出处:网络
I\'m using fo开发者_StackOverflow中文版rmtastic to generate a list of options in a select tag (eg. :as => :select) and I want a \"blank\" option, but this creates an XHTML warning (i.e. trimming empty

I'm using fo开发者_StackOverflow中文版rmtastic to generate a list of options in a select tag (eg. :as => :select) and I want a "blank" option, but this creates an XHTML warning (i.e. trimming empty

Looking at the source, it looks like formtastic is generating:

<option value=""></option>

Is there a way to customise how formtastic generates blanks options?


maybe options :prompt could help you?

  form.input :organization,  
    :collection => Organization.all(:order => :title),  
    :prompt => "some text"

have a good day!


Here are a answer with a similar issue :

Using :collection and :include_blank in Formtastic. How to do it?

He say if you add a :include_blank => true, it will work... For example:

f.input(:author, :as => :select, :include_blank => true)

In my case, i have a has_and_belongs_to_many association, and automatically have a blank option.

f.input :groups, :as => :check_boxes, :collection => current_admin_user.groups.order("created_at ASC").all

I follow this guide : https://github.com/justinfrench/formtastic#the-available-inputs

I hope to help!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号