I have a link_to_remote that updates the content of a hidden div and makes it appear.. But I want it to hide the div and not execute the link_to_remote function on the second click. What''s the best way to do this? I''m thinking I can do it in RJS maybe, but I''m not sure if there''s a nice Rails-y way to tell if a div is hidden or not.. I''d also need to conditionally do the :loading and :success effects (show/hide spinner) -- Posted via http://www.ruby-forum.com/.
Use the prototype function Element.toggle for toggeling an element on and off. On 4/5/06, Alex Nobert <ilament@gmail.com> wrote:> > I have a link_to_remote that updates the content of a hidden div and > makes it appear.. But I want it to hide the div and not execute the > link_to_remote function on the second click. What''s the best way to do > this? I''m thinking I can do it in RJS maybe, but I''m not sure if > there''s a nice Rails-y way to tell if a div is hidden or not.. > > I''d also need to conditionally do the :loading and :success effects > (show/hide spinner) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060405/e874d0aa/attachment.html
Daniel ----- wrote:> Use the prototype function Element.toggle for toggeling an element on > and > off.Yes I know about that but you didn''t answer the actual question: I want to have different behavior when it''s being shown than when it''s being hidden, which I cannot accomplish by just using Element.toggle -- Posted via http://www.ruby-forum.com/.
I think with a link_to_remote, it will call the action regardless. I think you would need to handle the login in the controller or RJS template. On 4/5/06, Alex Nobert <ilament@gmail.com> wrote:> > Daniel ----- wrote: > > Use the prototype function Element.toggle for toggeling an element on > > and > > off. > > Yes I know about that but you didn''t answer the actual question: > > I want to have different behavior when it''s being shown than when it''s > being hidden, which I cannot accomplish by just using Element.toggle > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060405/673923d9/attachment.html
Daniel ----- wrote:> I think with a link_to_remote, it will call the action regardless. I > think > you would need to handle the login in the controller or RJS template.What I''m doing for the time being is in an RJS file: page << "if(Element.getStyle(''show"+params[:id]+"'', ''display'') == ''none'') {" page.replace_html ''show''+params[:id], :partial => ''short'' page.visual_effect( :blind_down, ''show''+params[:id] ) page << "} else {" page.visual_effect( :blind_up, ''show''+params[:id] ) page << "}" This is a pretty cheap hack as far as I''m concerned and I''d appreciate if someone could point me towards a cleaner solution. It also doesn''t stop the spinner from firing even on hide, which is annoying. I could in theory do the same if(Element.getStyle()) inside the :loading => '''' block.. but.. gross.. -- Posted via http://www.ruby-forum.com/.
Alex Nobert wrote:> I have a link_to_remote that updates the content of a hidden div and > makes it appear.. But I want it to hide the div and not execute the > link_to_remote function on the second click. What''s the best way to do > this? I''m thinking I can do it in RJS maybe, but I''m not sure if > there''s a nice Rails-y way to tell if a div is hidden or not.. > > I''d also need to conditionally do the :loading and :success effects > (show/hide spinner)Anyone ever come up with a good solution for this. I assume this is very common for users toggling detail information for list where they want to load the data on the first click, but just remove it on the second and so on. Anyone? -- 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 -~----------~----~----~----~------~----~------~--~---
Fredrik Thuresson wrote:> Alex Nobert wrote: > > I have a link_to_remote that updates the content of a hidden div and > > makes it appear.. But I want it to hide the div and not execute the > > link_to_remote function on the second click. What''s the best way to do > > this? I''m thinking I can do it in RJS maybe, but I''m not sure if > > there''s a nice Rails-y way to tell if a div is hidden or not.. > > > > I''d also need to conditionally do the :loading and :success effects > > (show/hide spinner) > > Anyone ever come up with a good solution for this. I assume this is very > common for users toggling detail information for list where they want to > load the data on the first click, but just remove it on the second and > so on.I just use two links that do two different things: the first link loads and displays the new content, and the second link hides the content. But you only display one link at any one time, so if they''re in the same place it just looks like one link that''s changing from "Show" to "Hide" or whatever. So when you click on the "Show" link, as well as loading and displaying the new content, it hides itself and displays the second link. And when you click on the "Hide" link that''s just been revealed, as well as hiding the new content, it also hides itself and re-displays the first link. The way I look at it is that you''ve got two fundamentally different actions going on, so you might as well use two different links. Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''d do it like so: <%=link_to_function "Link", "if(Element.visible(''divid'')) { Element.hide(''divid'') } else { " + remote_function(:url=>{:action=>"blah"}, :loading=>whatever) + "}" %> and you could write a helper function that would take the arguments name, element id and options and output the above too. Fredrik Thuresson wrote:> Alex Nobert wrote: > >> I have a link_to_remote that updates the content of a hidden div and >> makes it appear.. But I want it to hide the div and not execute the >> link_to_remote function on the second click. What''s the best way to do >> this? I''m thinking I can do it in RJS maybe, but I''m not sure if >> there''s a nice Rails-y way to tell if a div is hidden or not.. >> >> I''d also need to conditionally do the :loading and :success effects >> (show/hide spinner) >> > > Anyone ever come up with a good solution for this. I assume this is very > common for users toggling detail information for list where they want to > load the data on the first click, but just remove it on the second and > so on. > > Anyone? > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- padawan seeks advice from jedi masters to create toggle box via ajax/rjs before slitting wrists with ruby powered light-saber.
- Need help refactoring a controller, perhaps add threading?
- ajax effects
- Using RJS to highlight one LI if using insert_html on an UL?
- Hide/Show Div and link_to_remote