You are viewing limited content. For full access, please sign in.

Question

Question

Focus on last field filled out

asked on December 12, 2017

Is there a way when saving a form as a draft to have the form open to the last field filled as a focus. I have an idea of having a field that saves the current field that is being filled out. I'm just wondering if there is a way to jump to that field when the form is loaded for the user.

0 0

Answer

SELECTED ANSWER
replied on December 28, 2017

I tried this on Chrome and IE and it worked on both.

As you said there is value in the "save" field, is the filled value like "Field1"? Can you use the value in the "save" field and run script on Chrome console like this:

$('html, body').animate({
        scrollTop: $("#" + $('.save input').val()).offset().top
    }, 2000);

And see if the page could scroll to the right field?

Besides, I didn't add function for "focus" on the field; it just scrolls to the field.

If you would like to focus, you can use code $("#" + $('.save input').val()).focus()

1 0

Replies

replied on December 12, 2017

Hi Cristobal,

You can try script like this (the field used for save focus field has class 'save'):

$(document).ready(function(){
  if ($('.save input').val()) {
    $('html, body').animate({
        scrollTop: $("#" + $('.save input').val()).offset().top
    }, 2000);
  }
  $('input').focus(function(){
    if ($(this).attr('id') && $(this).attr('id').indexOf('Field') != -1) {
    	$('.save input').val($(this).attr('id'));
    }
  });
});

 

1 0
replied on December 13, 2017 Show version history

I'm still having some issues with this. I checked the data to verify that it is being stored and looked at correctly by using console logs. Does this only work for forms without page breaks or if you have to scroll a bit on the form?

0 0
replied on December 13, 2017

The script above did not consider pagination. If you used page breaks, try this script:

$(document).ready(function(){
  if ($('.save input').val()) {
    var field = $("#" + $('.save input').val());
    var page = $(field.parents(".cf-page"));
    var id = page.attr("id");
    if (!page.hasClass("active")) {
      $(".cf-page.active").removeClass("active");
      page.addClass("active");
      var nav = $("[page=" + id + "], [value=" + id + "]");
      if (nav.is("option")) {
        $(".cf-pagination-dropdown").val(id);
      }
      else {
        $(".active", nav.parents(".cf-pagination")).removeClass("active");
        nav.addClass("active")
      }
      $("#form1").trigger("updatePagination");
    }
    $('html, body').animate({
      scrollTop: field.offset().top
    }, 1000);
  }
  $('input').focus(function(){
    if ($(this).attr('id') && $(this).attr('id').indexOf('Field') != -1) {
    	$('.save input').val($(this).attr('id'));
    }
  });
});

 

0 0
replied on December 28, 2017

Is there any limitation to the type of browser. I have put in a field and gave it the css class save. The field has the data though nothing happens when I return the draft. The form just loads as is and there is no change for the focus. This also applies to the version without pagination.

0 0
SELECTED ANSWER
replied on December 28, 2017

I tried this on Chrome and IE and it worked on both.

As you said there is value in the "save" field, is the filled value like "Field1"? Can you use the value in the "save" field and run script on Chrome console like this:

$('html, body').animate({
        scrollTop: $("#" + $('.save input').val()).offset().top
    }, 2000);

And see if the page could scroll to the right field?

Besides, I didn't add function for "focus" on the field; it just scrolls to the field.

If you would like to focus, you can use code $("#" + $('.save input').val()).focus()

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.