views:

659

answers:

2

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?

+3  A: 

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.

Corban Brook
I don't understand this. In my example above, @my_object.is_disabled? is actually my own custom method on an object. The actual method name is "def is_locked?".
Olly
have you tried doing :disabled => false or :disabled => true to see if it turns off and on disabled on your text_field. Im not sure why it would not be working if your is_disabled? method is returning boolean.
Corban Brook
Corban - yes, my method returns a boolean. If I add the explicit ":disabled => false" then I get the same effect. Rails adds this code to the HTML: disabled="". I would assume that it should add nothing if the value of :disabled is false.
Olly
A: 

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.

Olly