Hi, I have observers for a group of radio buttons, an observe_field for each radio button (I think its not possible to have one observe_field for a group of radio buttons). Now, the problem is that when I click on one radio button, all the observers get trigerred, so the method which the observe_field calls gets the wrong result. I just want that method to get the radio button that is clicked, which seems quite obvious, no? Any idea how to do this? Help would be greatly appreciated! Thanks, Aditya -- Posted via http://www.ruby-forum.com/.
Aditya Rajgarhia wrote:> Hi, > > I have observers for a group of radio buttons, an observe_field for each > radio button (I think its not possible to have one observe_field for a > group of radio buttons). > > Now, the problem is that when I click on one radio button, all the > observers get trigerred, so the method which the observe_field calls > gets the wrong result. I just want that method to get the radio button > that is clicked, which seems quite obvious, no? > > Any idea how to do this? Help would be greatly appreciated! > > Thanks, > > AdityaI believe radio buttons all have same id/name. You can test the value of the button group by: $(''common-radio-button-id'').value == ''foo'' That should at least tell you whats selected. -- Posted via http://www.ruby-forum.com/.
Hello Aditya, Without seeing your code, I have to ask this; the radio buttons all share the same name (obviously, otherwise they wouldn''t be a radio buttons group ;) but, have you given each a unique id ? giving a unique id will then mean you can tie an ''observe_field'' onto each one in turn. The only other thought I have that could (perhaps) be done, is having some :with javascript that grabs the ''selected'' from the radio buttons and then passes this over to the observe_field function. That may mean you could only have one observe_field for all of them.. but.. totally untested and jst a theory ;) Let us know how it all turns out :) Regards Stef Aditya Rajgarhia wrote:> Hi, > > I have observers for a group of radio buttons, an observe_field for each > radio button (I think its not possible to have one observe_field for a > group of radio buttons). > > Now, the problem is that when I click on one radio button, all the > observers get trigerred, so the method which the observe_field calls > gets the wrong result. I just want that method to get the radio button > that is clicked, which seems quite obvious, no? > > Any idea how to do this? Help would be greatly appreciated! > > Thanks, > > Aditya > >
Thanks for the reply. Unfortunately the radio buttons have different id''s (though the same name). The ''value'' is appended to the id, which makes the id''s different for all the buttons. Which is why I need to have a different observer for each button (since the observer takes the id name). Moreover, $(''common-radio-button-id'').value doesn''t work. I get a parse error, so probably that syntax is incorrect. Also, I don''t know if the radio_button has a "value" method. I don''t see anything about it in the Rails API. Any other ideas?> > I believe radio buttons all have same id/name. You can test the value > of the button group by: > > $(''common-radio-button-id'').value == ''foo'' > > That should at least tell you whats selected.-- Posted via http://www.ruby-forum.com/.
Hi Aditya, Aditya Rajgarhia wrote: (1) > (I think its not possible to have one> observe_field for a group of radio buttons). >(2) > Now, the problem is that when I click on one radio> button, all the observers get trigerred,Given the observed behavior in (2), what makes you believe (1) ? Bill
> (1) > (I think its not possible to have one >> observe_field for a group of radio buttons). >> > (2) > Now, the problem is that when I click on one radio >> button, all the observers get trigerred, > > Given the observed behavior in (2), what makes you believe (1) ?Well, I don''t conclude (1) from (2). I believe (1) simply because as I said in the reply above, the ''value'' is appended to the id, which makes the id''s different for all the buttons. Which means that a single observe_field won''t work for a group of button. Actually I think I made a little mistake by saying that "when I click on one radio button, all the observers get trigerred". In fact, as one would expect, the observers that get triggered are the ones for the radio button that gets deselcted and the one that gets selected. -- Posted via http://www.ruby-forum.com/.
Hi Aditya, Can you tell me how to write observers with radio buttons. I am new to rails. Please send me code snippets if possible. Thanks, Nitin. Aditya Rajgarhia wrote:> Hi, > > I have observers for a group of radio buttons, an observe_field for each > radio button (I think its not possible to have one observe_field for a > group of radio buttons). > > Now, the problem is that when I click on one radio button, all the > observers get trigerred, so the method which the observe_field calls > gets the wrong result. I just want that method to get the radio button > that is clicked, which seems quite obvious, no? > > Any idea how to do this? Help would be greatly appreciated! > > Thanks, > > Aditya-- 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 -~----------~----~----~----~------~----~------~--~---
Hi Nitin, Please post the code you''re having trouble with. Or Google ''rails observe_field radio_button''. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---