Simple_form: Placeholder in simpleform association

Created on 23 Dec 2014  路  3Comments  路  Source: heartcombo/simple_form

Placeholder in rails simpleform association doesn't work. I have tried a different ways but nothing works for me. And this way does't work:

<%= f.association :sex, :placeholder => 'sex'  %>

Most helpful comment

Assuming the association field is a select (i.e. a drop down field), this may work for you:

<%= f.association :sex, prompt: 'sex' %>

I believe :placeholder is used for text input fields, (like the email and password fields in this bootstrap example: http://getbootstrap.com/css/#forms), while :prompt is used for select fields.

I hope this helps.

All 3 comments

Assuming the association field is a select (i.e. a drop down field), this may work for you:

<%= f.association :sex, prompt: 'sex' %>

I believe :placeholder is used for text input fields, (like the email and password fields in this bootstrap example: http://getbootstrap.com/css/#forms), while :prompt is used for select fields.

I hope this helps.

@gmrash what is your association rendering, a select with a list of items? This is the default, and html selects do not have the placeholder attribute, as you can see in this simple test on the console:

'placeholder' in document.createElement('input')
=> true
'placeholder' in document.createElement('select')
=> false

I believe you're looking for either include_blank or prompt options, please take a look at Rails collection_select to see which options are available (which is what's used by Simple Form).

I'm giving it a close, but please let me know if you're still having issues and we might reopen if needed. Thanks.

Was this page helpful?
0 / 5 - 0 ratings