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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sat, Mar 20, 2010 at 11:52 AM, Joshua Martin <josmar52789-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
: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 Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Mar 20, 2010 at 11:52 AM, Joshua Martin <josmar52...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 20 March 2010 18:52, Joshua Martin <josmar52789-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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... -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.