Wazery
Wazery

Reputation: 15863

Rails select tag with required true

I have the following select tag

<%= f.select :id, User.find(:all, :conditions => ["manager = ?", false]).collect {|u| [u.username, u.id]}, {:required => true}, {:class => "multiselect", :multiple => true} %>

I try to add :required => true to it, the view renders but :required => true doesn't work!.

Upvotes: 1

Views: 3040

Answers (2)

unmultimedio
unmultimedio

Reputation: 1244

Quite a bit late, but for anyone looking, checking at the reference, should go explicitly as the hash, so ruby interpreter doesn't get confused:

select(object, method, choices = nil, options = {}, html_options = {}, &block)

For this special case:

<%= f.select :id,
             User.find(:all, :conditions => ["manager = ?", false]).collect {|u| [u.username, u.id]},
             {:prompt => 'Select something'},
             {:required => true, :class => "multiselect", :multiple => true} %>

Upvotes: 1

carpamon
carpamon

Reputation: 6623

Try this:

<%= f.select :id, User.find(:all, :conditions => ["manager = ?", false]).collect {|u| [u.username, u.id]}, {:multiple => true}, :class => "multiselect", :required => true %>

Upvotes: 0

Related Questions