Simple_form: :prompt => "..." don't work

Created on 7 May 2011  路  17Comments  路  Source: heartcombo/simple_form

Hi

i use rails3.0.6 and simple_form 1.3.1,


= f.input :typee, :collection => link_collect, :label => false, :prompt => "..."


#link_collect
def link_collect
[['web', 1], ['wap', 2], ['iphone', 3], ['android', 4]]
end

but, the , :prompt => "..." , is not works for me ...

Most helpful comment

looks like something changed in new version of rails
this code works for me:

<%= f.association :user, include_blank: 'Select user' %>

ps. @nashby, sure: http://bit.ly/QcvzTx, somehow i missed it :(

All 17 comments

The prompt option does't a valid option for input helper. Please wrap this options inside input_html option like this:

=  f.input :typee, :collection => link_collect, :label => false, :input_html => { :prompt => "..." }

Actually, it's supposed to work this way. All options given to collection and datetime inputs that are not handled by SimpleForm - such as :prompt - are passed straight to the template method - such as collection_select or date_select for instance.

@ZhangHanDong there are some tests related to this in SF test suite. If it is not working I'll have to ask you to send a failing test case or an example app so we can look at the possible issue. Thanks.

You are right! Reopen it.

the following code is working for me:

= f.input :friend_category_id, :collection => FriendCategory.all.collect{|c| [c.name, c.id]}, :prompt => "閫夋嫨绉嶇被...", :label => false

but , when i coustom the helper method, like this :

  = f.input :typee, :collection => friend_link_typee_collect, :label => false, :prompt => "..."

  #helper method
  def friend_link_typee_collect
    [['web', 1], ['wap', 2], ['iphone', 3], ['android', 4]]
  end

it's not works.

I add the failing test case in this:
https://github.com/ZhangHanDong/simple_form/commit/1a696ca3f3af7ed83bf9cb2570caefeec96872ac

This is not a simple_form issue. It is how Rails work. The collection select only render the prompt option if the value of attribute on object is blank. See the rails code here: https://github.com/rails/rails/blob/v3.0.7/actionpack/lib/action_view/helpers/form_options_helper.rb#L601

You can try this modifying your tests like this:

  test 'input should not set include blank if prompt is given when custome collect method' do
    @new_user = setup_new_user(:id => 1, :name => "Jose", :age => nil)
    age_state_collect = [['baby', 1], ['adult', 16]]
    with_input_for @new_user, :age, :select, :collection => age_state_collect, :prompt => "Please select foo"

    assert_select 'select option[value=1]', 'baby'
    assert_select 'select option[value=16]', 'adult'
    assert_select 'select option[value='']', 'Please select foo'
  end

If you want that the prompt option is always added please use the :include_blank option.

@rafaelfranca thanks! i see. my column has default value.

still prompt doesn't work :-/
here is my code:

<%= f.association :user, prompt: 'Select user' %>

@msony did you read all discussion above? and what version of SimpleForm and Rails are you using?

looks like something changed in new version of rails
this code works for me:

<%= f.association :user, include_blank: 'Select user' %>

ps. @nashby, sure: http://bit.ly/QcvzTx, somehow i missed it :(

@msony right.

Oddly enough, despite prompt: "Select something" being used as an example in the README, only include_blank worked for me as well with simple_form 1.4.1. /cc @rafaelfranca

can't get it to work with dates...

    <%= f.input :passport_expiration_date, as: :date, prompt: {year: 'select year', ... } %>

@hananamar what version of Rails and Simple Form are you using?

rails 3.2.11
simple_form 2.1.0

@hananamar that's strange. Can you please provide a sample application that reproduces the error?

Sorry, my bad, forgot prompt only works when there is no default value...

just experienced the same as @olivierlacan if this is still a thing, shouldnt this be reflected in the README?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rottingcorpse picture rottingcorpse  路  5Comments

gdgp picture gdgp  路  4Comments

gmrash picture gmrash  路  3Comments

frankyston picture frankyston  路  4Comments

vdaubry picture vdaubry  路  4Comments