Some time ago I asked 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:
A search_form action prepares a complex form and submits a large
number of parameters to…
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.
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):
<% 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 %>
<% 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 %>
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.
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.
@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.
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.