This may seem like a bit of a silly question, but here''s the reason: I have an app where a large number of options may need to be selected. Some are simply on/off with a checkbox but others have an additional text input field associated with them. This is OK if users read the instructions or they only select an on/off option, but sometimes for the options with additional text they simply type into the input field and neglect to tick the box as well. One way around this would be to re-write the code to remove the requirement for checkboxes on everything, but before doing that I would like to try using observe_field to tick the box if they start typing text in the field. Is that possible? So far I have something like this: <%= observe_field "text_input[#{parameter}]", :update => "check_box[#{parameter}]", :parameters => 1, :frequency => 0.5 -%> This does not work. Is anyone able to suggest how this might be fixed? Thanks. -- Posted via http://www.ruby-forum.com/. -- 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.
You could use the JS onblur to enable the check box. <%= text_field_tag "text","field" :onblur => ''check_text_field_for_text(this)'' %> then use a js function to check the text box for text and set the checkbox accordingly. On Mar 30, 10:19 am, Milo Thurston <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> This may seem like a bit of a silly question, but here''s the reason: > > I have an app where a large number of options may need to be selected. > Some are simply on/off with a checkbox but others have an additional > text input field associated with them. This is OK if users read the > instructions or they only select an on/off option, but sometimes for the > options with additional text they simply type into the input field and > neglect to tick the box as well. One way around this would be to > re-write the code to remove the requirement for checkboxes on > everything, but before doing that I would like to try using > observe_field to tick the box if they start typing text in the field. Is > that possible? > > So far I have something like this: > > <%= observe_field "text_input[#{parameter}]", :update => > "check_box[#{parameter}]", :parameters => 1, :frequency => 0.5 -%> > > This does not work. Is anyone able to suggest how this might be fixed? > Thanks. > -- > Posted viahttp://www.ruby-forum.com/.-- 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.
Milo Thurston
2010-Mar-31 12:24 UTC
Re: observe_field, how to use input to toggle checkbox?
Chris Habgood wrote:> then use a js function to check the text box for text and set the > checkbox accordingly.Thanks. So, I now have this: <%= text_field_tag "text_value[#{var}]","", :onblur => "check_text_field_for_text(#{var})" -%> ...and: <script type=''text/javascript''> function check_text_field_for_text(field) { if (document.form_name.text_value[field].value == null) { document.form_name.tick_box[field].checked = true } } </script> Still no luck, though. Presumably I am not referencing the name of the checkbox correctly, but I am not sure of the nature of the error. -- Posted via http://www.ruby-forum.com/. -- 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.
Milo Thurston
2010-Apr-01 15:09 UTC
Re: observe_field, how to use input to toggle checkbox?
I have finally had some success, and it turns out that it was as simple as this: <%= observe_field("text_input_#{parameter}",:function => "check_box_#{parameter}.checked=true") -%> -- Posted via http://www.ruby-forum.com/. -- 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.