Watts-Lab / surveys

Library of surveys for deliberation experiments
MIT License
3 stars 4 forks source link

Add `templateData` dictionary prop and template completion to SurveyWrapper #3

Open JamesPHoughton opened 2 years ago

JamesPHoughton commented 2 years ago

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