Skip to main content

CustomResponse

Defined in: parser/types.ts:1190

The CustomResponse interface is used to define the properties of a response rendered by React code in src/public. This is useful when built-in response types do not fit the interaction you need, but you still want the response to participate in the standard form, validation, provenance, and answer-saving flow.

Unlike other response assets, the path for a custom response is relative to the src/public/ folder. Similar to React stimulus components, we suggest creating a folder named src/public/{studyName}/assets to house custom response files for a particular study. The React component must be the default export from the file. You may also optionally export a named validate function from the same module.

Example:

{
"id": "custom-chart-response",
"type": "custom",
"prompt": "Use the custom response to select a chart and confidence.",
"path": "my_study/assets/CustomChartResponse.tsx",
"parameters": {
"chartOptions": ["Bar", "Line", "Scatter"]
},
"default": {
"chartType": "Bar",
"confidence": 70
}
}

Extends​

Properties​

PropertyTypeDescriptionOverridesInherited fromDefined in
default?JsonValueThe default value of the response. Must be JSON-serializable.--parser/types.ts:1197
delay?numberDelay in milliseconds before an element activates. Must be non-negative; defaults to 0 meaning the element is always active. Minimum 0-BaseResponse.delayparser/types.ts:520
excludeFromRandomization?booleanExclude response from randomization. If present, will override the responseOrder randomization setting in the components. Defaults to false.-BaseResponse.excludeFromRandomizationparser/types.ts:516
hidden?booleanControls whether the response is hidden.-BaseResponse.hiddenparser/types.ts:506
idstringThe id of the response. This is used to identify the response in the data file.-BaseResponse.idparser/types.ts:486
infoText?stringThe description that is displayed when the participant hovers over the response. This does not accept markdown.-BaseResponse.infoTextparser/types.ts:494
location?ConfigResponseBlockLocationControls the response location. These might be the same for all responses, or differ across responses. Defaults to belowStimulus-BaseResponse.locationparser/types.ts:498
onSubmit?GlobalStoreAction[]Apply these actions to the final submitted answer, in declared order.-BaseResponse.onSubmitparser/types.ts:484
paramCapture?stringUse to capture querystring parameters in answers such as participant_name. See the examples for how this is used, but prefer uiConfig.urlParticipantIdParam if you are capturing a participant ID.-BaseResponse.paramCaptureparser/types.ts:504
parameters?Record<string, unknown>Parameters passed to the custom response component.--parser/types.ts:1195
pathstringThe path to the react component. This should be a relative path from the src/public folder.BaseResponse.path-parser/types.ts:1193
promptstringThe prompt that is displayed to the participant. You can use markdown here to render images, links, etc.-BaseResponse.promptparser/types.ts:490
required?booleanControls whether the response is required to be answered. Defaults to true.-BaseResponse.requiredparser/types.ts:496
requiredLabel?stringYou can provide a required label, which makes it so a participant has to answer with a response that matches label.-BaseResponse.requiredLabelparser/types.ts:502
requiredValue?unknownYou can provide a required value, which makes it so a participant has to answer with that value.-BaseResponse.requiredValueparser/types.ts:500
secondaryText?stringThe secondary text that is displayed to the participant under the prompt. This does not accept markdown.-BaseResponse.secondaryTextparser/types.ts:492
style?StylesYou can set styles here, using React CSSProperties, for example: {"width": 100} or {"width": "50%"}-BaseResponse.styleparser/types.ts:514
stylesheetPath?stringThe path to the external stylesheet file.-BaseResponse.stylesheetPathparser/types.ts:512
type"custom"---parser/types.ts:1191
visibleIf?ResponseVisibilityConditionShow this response only when another response in this component satisfies the condition.-BaseResponse.visibleIfparser/types.ts:518
withDivider?booleanRenders the response with a trailing divider. If present, will override the divider setting in the components or uiConfig.-BaseResponse.withDividerparser/types.ts:508
withDontKnow?booleanRenders the response with an option for "I don't know". This counts as a completed answer for the validation.-BaseResponse.withDontKnowparser/types.ts:510