Hello: I have radio buttons like this: <% fields_for :goalhist do |g| %> <table> <tr> <td align=left><%= radio_button_tag (''duedate'', 0, checked = false, options = {:onclick => ""}) %> Start now </td> </tr> <tr id="detailed" style="display: none"><td colspan=2> </td></tr> <tr> <td align=left><%= radio_button_tag (''duedate'', 1, checked = false, options = {:onclick => ""}) %> Already started! </td> </tr> </table> <% end %> So, they behave fine; but, what''s interesting is that when I popuulate the onclick methods, the checking of the radio buttons no longer responds. If I leave those methods unpopulated, they perform fine. Here''s my populated code: <% fields_for :goalhist do |g| %> <table> <tr> <td align=left><%= radio_button_tag (''duedate'', 0, checked = false, options = {:onclick => "new Effect.Fade(''duedate''); return false;"}) %> Start now </td> </tr> <tr id="detailed" style="display: none"><td colspan=2> </td></tr> <tr> <td align=left><%= radio_button_tag (''duedate'', 1, checked = false, options = {:onclick => "new Effect.SlideDown(''duedate''); return false;"}) %> Already started! </td> </tr> </table> <% end %> Any ideas? Only thing else you might need to know is that the "fields_for" exists within another "form_for" tag. Thank you so much in advance! Mike -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mike Dershowitz wrote:> options = {:onclick => "new Effect.Fade(''duedate''); return false;"}) %>return true ? -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mike Dershowitz
2007-Feb-03 21:40 UTC
Re: Interesting radio button behavior with "onclick"
Phlip wrote:> Mike Dershowitz wrote: > >> options = {:onclick => "new Effect.Fade(''duedate''); return false;"}) %> > > return true ? > > -- > Phlip > http://www.greencheese.us/ZeekLand <-- NOT a blog!!!Yep, that did it! Thank you so much! Any idea as to why? Mike -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 3, 4:40 pm, Mike Dershowitz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Phlip wrote: > > Mike Dershowitz wrote: > > >> options = {:onclick => "new Effect.Fade(''duedate''); return false;"}) %> > > > return true ? > > > -- > > Phlip > > http://www.greencheese.us/ZeekLand<-- NOT a blog!!! > > Yep, that did it! Thank you so much! > > Any idea as to why? > > Mike > > -- > Posted viahttp://www.ruby-forum.com/.I think that lets the click event bubble up to the default click handlers instead of stopping the chain. The default handler is what does the checking/unchecking. _Kevinj --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mike Dershowitz wrote:> radio_button_tag (''duedate'', 1, checked = false,options = {:onclick => "new Effect.SlideDown(''duedate''); return false;"}) I forgot to point something out about that style. Ruby functions can''t see variables on their command lines written like checked The value goes in, but the name of the variable on the left side of the assignment does not. Ruby doesn''t care if you wrote monkey= or spider= or nothing there. So prefer nothing; programs should have as few moving parts as possible! -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mike Dershowitz
2007-Feb-04 15:46 UTC
Re: Interesting radio button behavior with "onclick"
Phlip wrote:> Mike Dershowitz wrote: > >> radio_button_tag (''duedate'', 1, checked = false, > options = {:onclick => "new Effect.SlideDown(''duedate''); return > false;"}) > > I forgot to point something out about that style. > > Ruby functions can''t see variables on their command lines written like > checked> > The value goes in, but the name of the variable on the left side of > the assignment does not. Ruby doesn''t care if you wrote monkey= or > spider= or nothing there. So prefer nothing; programs should have as > few moving parts as possible! > > -- > Phlip > http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!Phlip: I was wondering about that - so thanks for clearing it up for me. Looks like the left-hand of the assignment is only helpful for the programmer and not for the framework. So whatever belongs in that position when the appropriate method is called is what rails is expecting. So that begets the question of how to handle empties or can you re-order if you use name assignments. Based on what you said here, seems like not? Is that correct? -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mike Dershowitz wrote:> I was wondering about that - so thanks for clearing it up for me. Looks > like the left-hand of the assignment is only helpful for the programmer > and not for the framework. So whatever belongs in that position when > the appropriate method is called is what rails is expecting. > > So that begets the question of how to handle empties or can you re-order > if you use name assignments. Based on what you said here, seems like > not? Is that correct?Inferior languages use two systems to name arguments - Hashes/Maps, and named parameters. So such a language, with a Ruby-like syntax, would permit this: foo( :arg1 = ''bar'', { :arg2 => ''baz'' } ) That requires a foo with this signature: foo(arg1, aMap) Ruby splits the difference by not using two systems there, only one. Using only one system, instead of two, is always a Good Thing - it''s an example of the DRY principle, Don''t Repeat Yourself. All Ruby arguments are positional, and arg1 may not follow aMap. But Ruby allows you to leave out the map notation {}. So this... foo(''bar'', :arg2 => ''baz'') ...is the only way to call foo(arg1, aMap). arg1 is not optional, but arg2 is. This technique returns incredible control to the function author. She or he can detect which argument is a Hash and proceed accordingly. A function could take only a map, for example, and the caller can pass named arguments in any order so long as their names match. Now read up on Hash#merge and Hash#update. You handle an empty by checking if aMap[:arg2] is nil, or simply by merging a default Hash into aMap before pulling its arguments. Or updating - I forget which. -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
>> Mike Dershowitz wrote: >> >>> radio_button_tag (''duedate'', 1, checked = false, >> options = {:onclick => "new Effect.SlideDown(''duedate''); return >> false;"})Another answer. Rails authors who cram huge long statements like that together should be lined up and smacked. options= there is a best-practice when you simply use it as an argument, to break up long lines: options = {:onclick => "new Effect.SlideDown(''duedate''); return false;"}) radio_button_tag (''duedate'', 1, false, options) Now you can actually see where expressions begin and end! The other way around, options= inside the method call, is also bad because I might think options is used somewhere below, and it isn''t. -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---