Reputation: 7758
I've just updated to Rails 2.3.2 from Rails 2.1 and noticed an issue with regards to using the :disabled
option on input fields.
Previously we were using this option as a boolean, so we would indicate whether or not we wanted to disable the fields based on a method on the object, e.g.
f.text_field :amount, :disabled => @my_object.is_disabled?, :class => 'my_class'
This works fine in Rails 2.1 -- if is_disabled?
returns true, the form field is disabled, otherwise it's not.
In Rails 2.3 however, this isn't the case. The form field is disabled regardless of the value of :disabled
.
Does this mean I'll have to put an if
statement around my f.text_field
declaration such as:
<% if @my_object.is_disabled? %>
<%= f.text_field :amount, :disabled => 'disabled', :class => 'my_class' %>
<% else %>
<%= f.text_field :amount, :class => 'my_class' %>
<% end %>
Surely I'm missing something here?
Upvotes: 2
Views: 8501
Reputation: 7758
Please ignore this thread. The issue I was having was actually with Javascript.
Adding :disabled => false adds "disabled=''" to the form field which correctly doesn't disable the form field after all.
Upvotes: 4
Reputation: 21378
They got rid of is_boolean_field? in rails 2.3. It is just boolean_field? now.
so:
f.text_field :amount, :disabled => @my_object.disabled?, :class => 'my_class'
should work fine.
Upvotes: 6