SurveyStack integration spike

Question

Can we hold the inputs provided to SurveyStack via the iFrame in LiteFarm. If we don’t currently, but could, I’d also like to know the best way to approach this.

 

Context

The use cases we’d like to support moving forward are:

  1. User answers 25+ questions via SurveyStack, completes their export, and realizes they did the wrong reporting period or some other small mistake. Rather than entering those 25+ responses again, they would like to “use previous previous answers”

  2. User submitted survey last year and nothing has changed on their farm or on the certifier forms (checking with SurveyStack team to understand if they have a concept of versioning). User wants to just re-use their previous answers - either by skipping survey and generating same responses or by pre-populating responses

  3. User gets half way through form and loses connectivity, wants to pick up where they left off

 

Investigation

by @Calum Murray on https://lite-farm.atlassian.net/browse/LF-2202

I’ve investigated how the storage works for SurveyStack. What I’ve found is that they use IndexedDB to store all the responses as a user fills out the survey. This way, if someone loses connectivity while filling out the form, the responses will be saved temporarily. However, there is a caveat to this: IndexedDB is not persisted by default, so if the user closes the tab all the data is lost. On top of this, IndexedDB only allows scripts to access instances with the same origin, so we can’t add a script which will persist the IndexedDB data as we are unable to access it.

In terms of tracking the inputs in the iframe, once again we would run into issues with cross-origin permissions, as browsers try and prevent sites from accessing data inside an iframe for XSS reasons.

Another issue I see coming up is that as far as I can tell there is not a way for us to enter default values into questions in a survey. Again because of origins and XSS protections, any scripts we write will be unable to interact with the SurveyStack questions.

One thing we may be able to do is to create a table in postgres to store past answers and give users a button on the frontend to autofill with last years answers. The survey object returned from the api has a version number and a revision history, so we would be able to validate whether or not the farmer would be able to use the previous year’s answers.

Beyond this, I image we will need to reach out to SurveyStack regarding how we could possibly store data and/or pre-fill it.