I have a form on my Ruby on Rails3 Application with a drop menu, this is my current code for the select option:
<%= f.select :phone_type, options_for_select(["Select One", "Cell", "Work", "Office", "Home", "Other"],:disabled => ["Select One"]), :class => 'genForm_dropBox' %>
From my understanding this should have "Select One" as the default option when someone opens the page, but if they don't select one of the other options an error displays when they hit submit.
This is true in Browsers like Safari and Chrome and IE7, but in Firefox and IE8 it shows "Cell" as the first option as Select One is disabled.
I'd like it to display "Select One" by default, but have it as an unusable option when they submit the form. Do I need to script this into the controller, or model? or do I have this coded in the form wrong?
for those looking to incorporate this feature, I've taken a new approach from the model end of things. Being that all fields are required to be filled out in order for the user to submit and not receive an error alert, I gave the "Submit One" option a default value of nothing. You can take a look at the following code to see how I did that.
<%= f.select :phone_type, options_for_select([["Select One", ""], "Cell", "Work", "Office", "Home", "Other"]), :class => 'genForm_dropBox' %>
This is a little cleaner:
<%= f.select :phone_type, [ 'Cell', 'Work', 'Office', 'Home', 'Other' ], :prompt => 'Select One' %>
The :prompt argument generates an option with an empty value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With