You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<td>Accesses the row name (the <code>value</code> property within objects in the <a href="https://surveyjs.io/form-library/documentation/api-reference/matrix-table-with-dropdown-list#rows"><code>rows</code></a> array). Use this placeholder if you need to distinguish between matrix rows.</td>
@@ -127,18 +147,26 @@ You can also use prefixes, such as `row`, `panel`, `parentPanel`, and `composite
127
147
<td>Accesses the row title (the <code>text</code> property within objects in the <a href="https://surveyjs.io/form-library/documentation/api-reference/matrix-table-with-dropdown-list#rows"><code>rows</code></a> array).</td>
Copy file name to clipboardExpand all lines: docs/how-to-save-and-restore-incomplete-survey.md
+43-46Lines changed: 43 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,32 +9,32 @@ Respondents may not complete your survey in a single session. In this case, you
9
9
10
10
## Restore Survey Progress from the `localStorage`
11
11
12
-
To save incomplete survey results locally, implement a function that stores them under a specified key in the `localStorage` (see the `saveSurveyData` function in the code below). Call this function within `SurveyModel`'s [`onValueChanged`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onValueChanged) and [`onCurrentPageChanged`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onCurrentPageChanged) event handlers to save the survey results each time users change a question value or switch between pages. When the survey is completed, submit final survey results to the server using the [`onComplete`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onComplete) event handler:
12
+
To save incomplete results locally, implement functions that store [survey data](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#data) and [UI state](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#uiState) under specified keys in the `localStorage` (see the `saveSurveyData` and `saveSurveyUIState` functions in the code below). Call these functions inside the `SurveyModel`'s [`onValueChanged`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onValueChanged) and [`onUIStateChanged`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onUIStateChanged) event handlers to capture updates whenever users change a value or modify the UI (for example, expand/collapse a question box or switch pages). When the survey is completed, submit the final results to the server and remove them from the `localStorage` using the [`onComplete`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onComplete) event handler:
13
13
14
14
```js
15
15
import { Model } from"survey-core";
16
16
17
17
constsurvey=newModel();
18
18
19
-
constSTORAGE_ITEM_KEY="my-survey";
19
+
constSTORAGE_ITEM_DATA_KEY="my-survey-data";
20
+
constSTORAGE_ITEM_UI_STATE_KEY="my-survey-state";
20
21
constSURVEY_ID=/* ... Getting the survey ID ... */;
To save incomplete results in a database, submit them to your server each time users change a question value or switch between pages and when they complete the survey. Handle the [`onValueChanged`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onValueChanged), [`onCurrentPageChanged`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onCurrentPageChanged), and [`onComplete`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onComplete) events for this purpose.
87
+
To save incomplete results in a database, submit them to your server each time users change a question value and when they complete the survey. Handle the [`onValueChanged`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onValueChanged) and [`onComplete`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onComplete) to trigger these updates.
88
+
89
+
Saving the UI state on a server usually isn't practical because it represents device-specific UI preferences, such as which questions are expanded or which page the respondent last viewed. These preferences are relevant only within the current browser session and do not affect actual survey results. For this reason, UI state is better stored locally using the `localStorage`. To do this, handle the [`onUIStateChanged`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onUIStateChanged) event.
90
90
91
91
```js
92
92
import { Model } from"survey-core";
93
93
94
94
constsurvey=newModel();
95
95
96
+
constSTORAGE_ITEM_UI_STATE_KEY="my-survey-state";
96
97
constSURVEY_ID=/* ... Getting the survey ID ... */
0 commit comments