Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bendik Engebretsen 105 posts 202 karma points
    Jan 28, 2016 @ 15:47
    Bendik Engebretsen
    0

    Maintain scroll position after HandleFormSubmit

    I have made a custom form for my Umbraco 7 site using the SurfaceController approach. But the thing is, my partial is located a bit down on the page and after the HandleFormSubmit and RedirectToCurrentUmbracoPage in the SurfaceController, the browser always scrolls to the top of the page, leaving the form out of view.

    Does anyone have a nice trick, maybe some js that I can put in the partial which makes sure the scroll position is retained after submitting the form?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 28, 2016 @ 15:59
    Ismail Mayat
    0

    Bendik,

    I did with setting a value in controller then in partial testing for that and writing out some js so in my base template i had:

        @if (TempData.ContainsKey("CommentSaved") || TempData.ContainsKey("CommentsSorted"))
    {
        TempData.Remove("CommentSaved");
        TempData.Remove("CommentsSorted");
        <script type="text/javascript">
            @if (Model.Content.DocumentTypeAlias == "Product")
            {
                //we need to show the comments tab
                @Html.Raw("$(function() {$('#commentLink').trigger('click');scrollToElement($('.tabcordion__tabs'));});")
            }
            else
            {
                @Html.Raw("$(function() {scrollToElement($('#comments--list'));});")
            }
        </script>
    }
    

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft