Question T438
Visible to All Users

populate survey form with previous entered data

created 7 years ago (modified 7 years ago)

Hi, is there any way could temporary save unfinished survey, that allows next time pull out the survey with previous saved data (as defult data)?

Answers

created 7 years ago

Thanks Andrew! this make sense to me, surveyModel wrapping data property that actually purposely stores the surveyData.

    created 7 years ago (modified 7 years ago)

    Hi, I have a pretty similar question here.

    I'm using dxsurvey to store partial survey results. I know I can retrieve the state of a survey by querying http://api.dxsurvey.com/Help/Api/GET-api-Survey-getSurveyAndIsCompleted_surveyId_clientId and looking at the isCompleted boolean.

    What I'd like is to pre-fill the survey if user has left it in a partial state.
    So my question is : is there an API endpoint on dxsurvey to fetch survey.data for a given clientId ?

    [Edit] : A quick solution is indeed to use localStorage, but i wonder about the need for the endpoint getSurveyAndIsComplete if it doesn't provide partial results from the clientId.

      Comments (1)

        Hello,
        We have discussed the ability to get the results by clientId. However, we could not add it into public API. It is not correct since knowing the survey and client Ids you will be able to get the client answers. It is unacceptable from security point of view.
        This functionality should be in the private API.
        I do not see a good solution here. except using the user browser local storage :(

        Thank you,
        Andrew
        SurveyJS Team

        created 7 years ago

        Sure, you can always access the survey results by survey.data property. The same way you can always assign your previous saved data to survey.data property as well.
        Here is the example: https://surveyjs.io/Examples/Library/?id=survey-data#content-js

        Thank you,
        Andrew
        SurveyJS Team

          Comments (3)

            Please take a look at this demo: https://surveyjs.io/Examples/Library/?id=real-patient-history#content-js
            It is a large patient history form. All results are saved into local storage and load from it as well. A user may leave survey at any time and comeback.
            All you need to do, is to change the local storage on your database.

            Thank you,
            Andrew
            SurveyJS Team

              Hello,
              You code looks just fine to me. I would do the same. Are you sure, you do not override survey.data later or recreate the survey completely?
              Any chance to get your code on plunker?
              If it is really hard to do, we may try to get this code for ng4.
              Although, there shoud not be a lot of difference between ng2 or ng4. In fact ng, as well as jQuery SurveyJS versions, are using knockout code with embedded knockout framework.

              Thank you,
              Andrew
              SurveyJS Team

                I see the problem now.

                JavaScript
                const surveyModel = new Survey.ReactSurveyModel(data); /// it is incorrect

                It should be:

                JavaScript
                const surveyModel = new Survey.ReactSurveyModel(YourSurveyJSON); surveyModel.data = data;

                Thank you,
                Andrew
                SurveyJS Team