Select Form Helper Required True Not Working
I'm doing a very simple select field in a form which looks like this:
<%= f.select :phys_option, options_for_select([["N/A", "n/a"], ["No", "no"], ["Yes", "yes"]], :selected => @run.phys_option), :include_blank => true, :required => true, :class => 'select' %>
This works with basic functionality, includes a blank option, and allows me to select the proper item from the array. But what doesn't work is the :required => true
and the :class => 'select'
arguments. I can submit the form without selecting anything and my select class (using select2 for dropdowns) doesn't work. Should these arguments be in a hash form instead? Or am I missing something simple here? I need the field to be required but don't want to do a model validation on it if I don't have to.
Thanks in advance, guys!
I figured this out. I had to include the arguments in a hash like so:
<%= f.select :phys_option, options_for_select([["N/A", "n/a"], ["No", "no"], ["Yes", "yes"]], :selected => @run.phys_option), {:include_blank => true}, {:required => true, :class => 'select'} %>
Ah yes, that's one of those odd gotchas because it accepts two hashes where as most of these methods accept only one. It's a tag with a whole lot of options, so it kind of makes sense, but seems a bit overly complicated.