Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formtastic - customise blank option in select tag

I'm using formtastic 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?

like image 900
BlueFish Avatar asked Jan 17 '11 21:01

BlueFish


2 Answers

maybe options :prompt could help you?

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

have a good day!

like image 172
andrea Avatar answered Nov 15 '22 14:11

andrea


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!

like image 4
CristianOrellanaBak Avatar answered Nov 15 '22 12:11

CristianOrellanaBak