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?

On Sat, Mar 20, 2010 at 11:52 AM, Joshua M. [email protected]
wrote:

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
successful:

http://www.w3.org/TR/html401/interact/forms.html#adef-disabled

What you probably want to use is “readonly”, defined immediately
following the above entry…


Hassan S. ------------------------ [email protected]
twitter: @hassan

: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.

On Mar 20, 9:02 pm, Hassan S. [email protected]

On 20 March 2010 18:52, Joshua M. [email protected] wrote:

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.

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…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs