Reputation: 1528
I am having trouble setting readonly => true on a form helper. It still allows me to change the selection. Here is my code.
<%= f.date_select :date_of_birth, {:order => [:day, :month, :year]}, {:readonly => true} %>
Upvotes: 2
Views: 9103
Reputation: 37915
The readonly
option does not exist in the HTML <select>
-tag or <otption>
-tag and even Rails cannot magically add such an option to HTML..!
Instead, you can use :disabled => true
, to show the select fields as 'disabled':
f.date_select :date_of_birth, {:disabled => true, :order => [:day, :month, :year]}
Values of disabled fields are not send with the form though, so if this is required, you need to add a copy of the field as hidden as well. This hidden field/value is then send with the form, and the disabled field is shown in on your page.
Upvotes: 3