Cart Licenses Contact Support Online Creator Log in/Register
Try
Buy
v 1.9.50

Continue an Incomplete Survey

Your respondents may not complete your survey in a single session. In this case, you can restore their answers from the previous session next time they get to the survey. Incomplete results can be loaded from your database or the browser's localStorage.

To save incomplete results, enable the Survey's sendResultOnPageNext property. With this setting, the Survey raises the onPartialSend event each time a respondent navigates to the next survey page. Handle this event to send incomplete results to your database or localStorage:

import { Model } from "survey-core";

const surveyJson = { ... };
const survey = new Model(surveyJson);

survey.sendResultOnPageNext = true;

const storageItemKey = "my-survey";

function saveSurveyData (survey) {
  const data = survey.data;
  data.pageNo = survey.currentPageNo;
  window.localStorage.setItem(storageItemKey, JSON.stringify(data));
}

// Save survey results
survey.onPartialSend.add((survey) => {
  saveSurveyData(survey);
});
survey.onComplete.add((survey) => {
  saveSurveyData(survey);
});

// Restore survey results
const prevData = window.localStorage.getItem(storageItemKey) || null;
if (prevData) {
  const data = JSON.parse(prevData);
  survey.data = data;
  if (data.pageNo) {
    survey.currentPageNo = data.pageNo;
  }
}

View example

See Also