Save and Restore a Survey JSON Schema
Survey Creator produces survey model schemas as JSON objects. You can persist these objects on your server or in the browser's localStorage
so that users can restore them and continue designing the survey from where they left off. In this example, Survey Creator automatically saves survey JSON schemas in the localStorage
. To try this functionality, modify the survey and reload the page—your changes will remain.
Persist Survey JSON Schemas
To save a survey JSON schema, implement the saveSurveyFunc
function. It accepts two arguments:
saveNo
An incremental number of the current change. Since web services are asynchronous, you cannot guarantee that the service receives the changes in the same order as the client sends them. For example, change #11 may arrive to the server faster than change #10. In your web service code, update the storage only if you receive changes with a highersaveNo
.callback
A callback function. Call it and passsaveNo
as the first argument. Set the second argument totrue
orfalse
based on whether the server applied or rejected the change.
You can access the raw survey JSON schema using the SurveyCreatorModel
's JSON
property or its stringified version using the text
property. Save the content of one of these properties to the preferred storage.
Enable Auto-Save
The saveSurveyFunc
function is called each time a survey JSON schema needs to be saved. Users can run the save operation by clicking the Save button in the toolbar. Alternatively, you can enable auto-save. This feature starts the save operation when the survey JSON schema is modified.
To activate auto-save, set the isAutoSave
property to true
, as shown in this demo. Note that the Save button becomes unavailable. To avoid overloading the server with frequent requests, survey modifications are saved with a 500 ms delay. You can use the autoSaveDelay
property to increase or decrease this value.