Some of the surveys we work with will need to be populated with data from the rest of the experiment. For example, if we ask about out-party affect, we may want to ask:
"Please rate your level of warmth towards members of the {otherParty} party"
where {otherParty} is a placeholder for a value that will depend on which party the participant has previously indicated as their own. As each survey may have different placeholders, we want to make it easy to pass particular template fields to the survey without needing to hard code them. One way to do this is with an optional prop called templateData.
The surveyjs library has some syntax for using the results of one question as a template value in another question - we need to make sure that our template filling plays nicely with this. I don't know if this syntax can also handle a dictionary of template fields supplied externally. If so, we should tap into that functionality. Otherwise, we may need to modify the surveyJson element before we pass it to SurveyJS.
If we need to do our own template substitutions, there is probably a javascript best practice for doing so. We should use a library rather than roll our own code for this, because there are likely to be some serious edge cases we don't have time to think through.
This issue is ready to merge/close when
[ ] SurveyWrapper and its propTypes are updated to include the templateData prop, and modify the survey
[ ] example_survey.json is updated to include 3 different placeholders to be populated, at least one of which is used twice in the survey, and one of which overlaps with the name of an existing question
[ ] example_survey.stories.mdx is updated to document the templateData that the survey expects
[ ] The survey substitution is demonstrated on chromatic
[ ] Documentation is written (in the repository README.md) for:
[ ] how to write a survey as a template that can be populated with templateData
[ ] how to format the templateData dictionary
[ ] Tests are written to check that:
[ ] Template fields in surveys are correctly filled with values from the data dictionary
[ ] When a template field is used multiple times, the same value is populated in each
[ ] When a template field in the survey is not found in the data dictionary (and is not the name of another question in the survey, from which answers can be populated) an error is raised
[ ] When a key of a data dictionary is not found in the survey template, a warning is raised
[ ] When a key from the dictionary is identical to a question name (so that there may be a namespace conflict) a warning is raised and the value from the data dictionary is used
Some of the surveys we work with will need to be populated with data from the rest of the experiment. For example, if we ask about out-party affect, we may want to ask:
where
{otherParty}
is a placeholder for a value that will depend on which party the participant has previously indicated as their own. As each survey may have different placeholders, we want to make it easy to pass particular template fields to the survey without needing to hard code them. One way to do this is with an optional prop calledtemplateData
.The surveyjs library has some syntax for using the results of one question as a template value in another question - we need to make sure that our template filling plays nicely with this. I don't know if this syntax can also handle a dictionary of template fields supplied externally. If so, we should tap into that functionality. Otherwise, we may need to modify the
surveyJson
element before we pass it to SurveyJS.If we need to do our own template substitutions, there is probably a javascript best practice for doing so. We should use a library rather than roll our own code for this, because there are likely to be some serious edge cases we don't have time to think through.
This issue is ready to merge/close when
propTypes
are updated to include thetemplateData
prop, and modify the surveyexample_survey.json
is updated to include 3 different placeholders to be populated, at least one of which is used twice in the survey, and one of which overlaps with the name of an existing questionexample_survey.stories.mdx
is updated to document thetemplateData
that the survey expectstemplateData
templateData
dictionarydata
dictionary