Disabled Text_Field Value Not Saved

I have a text_field that stores an invoice due date. It's value is
updated by JQuery when the user specifies the terms of the invoice.
So, the value would become the Invoice Date + Terms.

The text_field should be disabled so that the user can't put it a
random date without regard to the terms or invoice date.

However, adding the :disabled attribute to the text_field, or adding
the disabled attribute via JQuery results in the value not being saved
when the invoice is created.

How can I make the value of the disabled text_field be recorded during
the @invoice.save?

You can't because, by definition, a disabled control cannot be


What you probably want to use is "readonly", defined immediately
following the above entry...

:readonly => true was the perfect solution for this problem! Thanks!

For future readers' reference, the text_field now looks like this:

<%= text_field "invoice", "due_date", :readonly => true, :class =>
'textbox' %>

This allows the visitor to see the field's content, but not edit it.

So what stops them writing their own form and posting whatever value
they want? Or using some DOM manipulation tools (Firebug?) to tweak
the value?

If you are calculating the value of the field client-side using JS,
you shouldn't *trust* the returned params value server-side. It would
be trivial to re-do in the controller whatever calculation you're
doing on the client to guarantee the saved value is correct.

This would then allow you to do anything you like with the JS
client-side; update a text box as you are, or the contents of a span;
don't stress about whether the textbox is read-only (because you're
not using its return value), and worry less about whether the user's
browser has JS support at all...