cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Dumon <>
Subject Re: No ajax, but page with long repeater...
Date Sat, 11 Mar 2006 12:00:26 GMT
On Fri, 2006-03-10 at 14:42 -0500, David Park wrote:
> Using cocoon 2.1.8, here is the problem:
> Say a form has a repeater with many rows. If there is a repeater-action 
> at the bottom that adds a new row, clicking it causes a form submit, and 
> the user ends up at the top of the page, where the new row sits at the 
> bottom of the page.
> Likewise, if the repeater rows themselves have nested repeaters, any 
> action that causes a form submission leaves the user at the top of the 
> page, in a different "context", if you will, than where they performed 
> the "submit action".
> Is it possible, without ajax, to have a page submission target the 
> widget that was "acted upon"?
> Is CForms able to output an <a name="repeteater-row-id"> that is 
> targeted somehow via an http://my_continuation_url#repeater-row-id?
> Many thanks to anyone who has any assistance to offer.

Another approach I once used in the past was to store the scroll
position (in pixels) in a hidden input field when submitting the form,
and restoring it when displaying the form.

You could add a hidden field widget for this purpose.

Here's some code I found back:

<script type="text/javascript">
  var storeScrollOnSubmitHandler = new Object();
  storeScrollOnSubmitHandler.forms_onsubmit = function() {
      var scrollPos = window.pageYOffset; // Mozilla
      if (scrollPos == undefined) {
          if (document.compatMode &amp;&amp; document.compatMode != "BackCompat")
              scrollPos = document.documentElement.scrollTop;
              scrollPos = document.body.scrollTop;
      if (scrollPos != undefined) {
          document.forms["editdoc"].scrollPosition.value = scrollPos;

  var setScrollPosHandler = new Object();
  setScrollPosHandler.forms_onload = function() {
      function restoreScroll() {
          var scrollPos = document.forms["editdoc"].scrollPosition.value;
          if (scrollPos != null &amp;&amp; scrollPos != "")
             window.scrollTo(0, scrollPos);
      setTimeout(restoreScroll, 200);

This code assumes there's a field called "scrollPosition" on a form
named "editdoc", so you'll need to change at least that. I see the
restore is done via a timeout -- I don't remember why that was, you
might try to remove that. Also I just changed some things to the
restoreScroll function which might not work (e.g. it could be that you
need to parse the scrollPos to a number). Anyhow, this should get you

Bruno Dumon                   
Outerthought - Open Source, Java & XML Competence Support Center                

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message