0

I am using fullcalendar in my code and I want to adjust the scroll position after (and only after) an event is clicked. I can do that by having $(window).scrollTop($("#MyId").offset().top) in eventclick but my problem is that i need to submit a form on each click as well and that causes a page reload. so i lose my scroll position. i can't do the scroll positioning in eventAfterAllRender or loading either, since i only want it to happen after an eventclick. Is there anyway I can know that reload is happening after an eventclick? not for example, after choosing a new date on the calendar? I really tried everything which came to my mind but I didn't get anywhere. any idea would be appreciated :)

Update: Part of the code I was trying to explain: the eventClick option of my fullcalendar:

 eventClick: function (calEvent, jsEvent, view) {

$(window).scrollTop($("#IdOfTheDivIWantToJumpToAfterAnEventIsClicked").offset().top);

// Now I need To submit my form everytime I click on an event which makes the page loses scroll position.


            $("#MyForm").submit();
        },

I hope it is clearer now..

  • A small image explaining scenario or code would help. We are shooting in the dark here. –  Jul 17 '14 at 10:35
  • I hope am clearer now.. it is the eventclick option of my fullcalendar. i lose my window scroll bar position due to the form submission i need to do on each event click. –  Jul 17 '14 at 10:46
  • When you submit the form, the page will be redirected right? –  Jul 17 '14 at 12:09
  • well.. when i click on an event, another container on the same page gets populated with the right information related to that event ( but yes, url is set in "event" and it sends data to the right action in my controller ).. the page is the same, but each eventclick has a form submit and reloads the same page. so when by each click, page is scrolled to the right div, the scroll position is lost by form submit and page reload. –  Jul 17 '14 at 13:09
  • Basically you want to retain page scroll even after page reload.. Is that what you want? If that is the case, [here's](http://stackoverflow.com/questions/17642872/refresh-page-and-keep-scroll-position) a question that might help you. –  Jul 18 '14 at 03:59

1 Answers1

0

What I ended up doing: I added a hidden input field to my form and when an event is clicked, I filled up the input field value with a string (for example "Clicked")

eventClick: function (calEvent, jsEvent, view) {
            $("#MyNewHiddenInputField").val("Clicked");
            $("#MyForm").submit();
        }

Then if this input field is filled with a value (which happens only by a click on an event), I fill the hidden field value through my controller on form submit to save the hidden field value after the page reload.

and after i used this value in fullcalendar loading, i just remove its value..

loading: function (isLoading, view) {
            // some code
            if (isLoading) {
                //some code
            } else {

                if ($("#MyNewHiddenInputField").val() == "Clicked" && // some other conditions) {
                    // Do what you wanna do
                }


                // Now clear my hidden field
                $("#Clicked").val("");
            }
        }

therefore, page load after an event click will be recognized from other type of loading. i hope am clear!

i am not sure if there is any better way to do it, if i come across a better solution, i will update my answer :)