dimah-surveyv0.5.0
Surveys

Responses

Start a response, save progress, and check the submission.

startResponse attaches the current published survey to the response. getResponse returns that document as definition. A later publish does not replace it, and submit is checked against it.

A response stores the answers and the survey needed to read them.

import type { ResponseRecord } from "@dimah-survey/core";

Prop

Type

Status

StatusMeaningNext
draftAnswers may still be incompleteSave, submit, or abandon
submittedThe stored survey accepted the answersReopen, or submit the same data again
abandonedClosed without a submissionReopen

Operations

OperationEffect
startResponseOpen a draft, or return the one collection settings select
savePartialReplace data on a draft
submitResponseCheck the stored survey and save the accepted answers
abandonResponseClose a draft. The answers stay as they are
reopenResponseMove a submitted or abandoned response back to draft

Save and abandon require a draft. Reopen requires settings.reopen: true and a submitted or abandoned response.

Save progress

Partial save replaces the whole data object. It does not patch individual keys.

By default the server loads the stored survey, assigns the posted answers, runs clearIncorrectValues(true), and stores the resulting survey.data. Required questions are checked on submit, so an incomplete draft can be saved.

Set sanitizePartial: "replace" to store the payload as sent.

Questions with choicesByUrl keep the posted value. The server does not fetch that URL.

Submit

The default validateResult loads the survey stored on the response, drops values that cannot be assigned, runs SurveyJS validate(), and returns the survey.data to store. An invalid result throws VALIDATION_FAILED. questions lists the failing question names.

Replace validateResult when the application needs its own checks. It always receives the stored survey. Return the object to store, return nothing to keep the input, or throw an APIError to reject it. See Configuration.

Submitting a row that is already submitted returns that row when the cleaned payload matches stored data. Omitting data does the same. A different payload fails with RESPONSE_CLOSED.

Hooks

onStart runs only before a new insert. onSubmit runs after validation and before the submitted write. Throwing from either callback aborts the write.

afterStart and afterSubmit run after the row is stored. A failure there leaves the write in place. Submitting the same data again does not run the submit hooks a second time.

Concurrent writes

Partial save, submit, abandon, and reopen accept expectedUpdatedAt from the last read. The comparison happens inside the write. A mismatch fails with STALE_UPDATE.

useSurveyResponse sends the token it last read. On STALE_UPDATE it sets stale and leaves the model mounted. Call reload to read the stored response again.

Omit the token only when the last write should win.

Reading responses

listResponses returns summaries. include: "full" adds data and returns each referenced survey document once on versions. Only the editor audience can request it. Join a row's versionId to that list. getResponse returns definition on the single row.

import type { ResponseSummary } from "@dimah-survey/core";

Prop

Type

Pagination and filters are listed in the HTTP protocol.

On this page