Hi, I hope someone can help me with this. I have a pretty long form (which involves scrolling). After posting the form, some data gets validated and if there are errors the form is rendered again and the errors are shown. The problem is: when the form gets rendered the scroll bar is always at the top, instead of at the part of the form where the error happened. I tried using redirect_to :anchor => ''bla'', but when I use that the values the user entered are gone. What I want to do is render :action => bla, :anchor => ''bla'', but obviously this doesn''t work. I can''t see how to do this. Does anyone have an idea??? Thanks, Mischa. -- http://boxroom.rubyforge.org -- 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 -~----------~----~----~----~------~----~------~--~---
My suggestion would be to use ajax to post the errors into an initially empty DIV. The easiest way to do this is to use an RJS template for the response to the form. Ajax on Rails has a good treatment of this. Michael On Jun 6, 12:54 pm, Mischa Berger <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > I hope someone can help me with this. > > I have a pretty long form (which involves scrolling). After posting the > form, some data gets validated and if there are errors the form is > rendered again and the errors are shown. > > The problem is: when the form gets rendered the scroll bar is always at > the top, instead of at the part of the form where the error happened. I > tried using redirect_to :anchor => ''bla'', but when I use that the values > the user entered are gone. > > What I want to do is render :action => bla, :anchor => ''bla'', but > obviously this doesn''t work. I can''t see how to do this. Does anyone > have an idea??? > > Thanks, > Mischa. > > --http://boxroom.rubyforge.org > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the tip. I found another workaround... It may not look so nice, but it works: If an error occurs, call a javascript that scrolls to the anchor: <% if flash[:cancel_error] %> <script type="text/javascript">window.onload = scrollToError;</script> <a name="error"></a><br /> <div id="error"><%= flash[:cancel_error] %></div> <% end %> function scrollToError(){ window.location.hash = ''#error''; } -- 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 -~----------~----~----~----~------~----~------~--~---