Some time ago I <a href="http://www.ruby-forum.com/topic/127406#new">asked</a> about the use of javascript "please wait" messages whilst a big query runs. Now I am back to working on this code I need to deal with this problem and have had no luck finding anything that works. The setup is as follows: 1. A search_form action prepares a complex form and submits a large number of parameters to... 2. A big_query action which takes some time to run and then renders its big_query view. Until (2) has finished running users see the view of (1) with no clue that anything is actually happening. So, ideally some sort of javascript that would clear away the form in (1) and replace with the waiting message the moment the "submit" button is clicked would suit. But, I can''t find any means of both submitting the form and running the javascript. Perhaps it is form_remote_tag, but the syntax for this is not at all clear. Perhaps something like this in search_form.rhtml: <div> <div id="spinner" style="display:none;"><img src="/images/loading.png"></div> <div id="hide_me"> <%= form_remote_tag({ :action => ''big_query'', :loading => "Element.show(''spinner'')", :complete => "Element.hide(''spinner'')", :update => "hide_me"}) %> <!-- big form goes here --> <%= submit_tag %> </form> </div> </div> Any clarification as to how this should work would be most welcome - 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-/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 -~----------~----~----~----~------~----~------~--~---
Milo Thurston wrote:> <%= form_remote_tag({ :action => ''big_query'', :loading => > "Element.show(''spinner'')", :complete => "Element.hide(''spinner'')", > :update => "hide_me"}) %>The values of the :loading and :complete keys are just JavaScript, so you can have any amount of stuff in there. The following should work (not tested it, though): <div id="hide_me"> <% form_remote_tag :url => {:action => :big_query}, :loading => "Element.hide(''hide_me''); Element.show(''spinner'')", :complete => "Element.hide(''spinner''); Element.show(''hide_me'')", :update => "hide_me" do %> form stuff in here <% end %> </div> Arguments are the same as link_to_remote. -- 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 -~----------~----~----~----~------~----~------~--~---
Mark Bush wrote:> <div id="hide_me"> > <% form_remote_tag :url => {:action => :big_query}, > :loading => "Element.hide(''hide_me''); Element.show(''spinner'')", > :complete => "Element.hide(''spinner''); Element.show(''hide_me'')", > :update => "hide_me" do %> > form stuff in here > <% end %> > </div>Thanks, that''s a lot better than I''ve been getting so far. The only problem seems to be that the app wants to render everything within the same page afterwards, so if the user is re-directed (e.g. to login) then the page ends up looking rather odd. That''s presumably my lack of understanding of how rendering works, though. -- 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 26 Mar 2008, at 11:02, Milo Thurston wrote:> > Mark Bush wrote: >> <div id="hide_me"> >> <% form_remote_tag :url => {:action => :big_query}, >> :loading => "Element.hide(''hide_me''); Element.show(''spinner'')", >> :complete => "Element.hide(''spinner''); Element.show(''hide_me'')", >> :update => "hide_me" do %> >> form stuff in here >> <% end %> >> </div> > > Thanks, that''s a lot better than I''ve been getting so far. > The only problem seems to be that the app wants to render everything > within the same page afterwards, so if the user is re-directed (e.g. > to > login) then the page ends up looking rather odd. That''s presumably my > lack of understanding of how rendering works, though. >That is an unfortunate truth: the browser hides the behind the scenes redirect from the javascript (at least in firefox it does) so it just sees the final result without knowing that a redirect has happened. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
@Milo -- It may be obvious to you know, but when you use form_remote_tag the form expects javascript back presumably with the intention of changing one or more elements on the page. If your "big_query" that renders a "big_view" was previously using a full postback then you need another solution. Maybe some js hooked to the button (onclick) or form (onsubmit)? submit_tag "Start big query", :onclick=>"function(){$ (''spinner'').show(); return true;}" The key is making sure you return true. That lets the form know that the click still needs the default handling available from the form. I think you should be able to do something like this to display a ''wait'' message; the view rendering or re-direct will take care of replacing the page when it''s ready. On Mar 26, 7:02 am, Milo Thurston <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Mark Bush wrote: > > <div id="hide_me"> > > <% form_remote_tag :url => {:action => :big_query}, > > :loading => "Element.hide(''hide_me''); Element.show(''spinner'')", > > :complete => "Element.hide(''spinner''); Element.show(''hide_me'')", > > :update => "hide_me" do %> > > form stuff in here > > <% end %> > > </div> > > Thanks, that''s a lot better than I''ve been getting so far. > The only problem seems to be that the app wants to render everything > within the same page afterwards, so if the user is re-directed (e.g. to > login) then the page ends up looking rather odd. That''s presumably my > lack of understanding of how rendering works, though. > > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
AndyV wrote:> If your > "big_query" that renders a "big_view" was previously using a full > postback then you need another solution.What I did was move big_query.rhtml to _big_query.rhtml and added "render_partial" to the end of the action in the controller. This seems to do what is required, but I''ll give your suggestion a try as well. -- 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 -~----------~----~----~----~------~----~------~--~---