surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.23k stars 820 forks source link

Pre-filling checkbox values isn't working for surveys loaded from survey creator #2558

Open notz opened 4 years ago

notz commented 4 years ago

Are you requesting a feature, reporting a bug or asking a question?

Bug

What is the current behavior?

Starting a survey loaded from survey creator with pre-filled data, the checkbox items should also be set/unset according the pre-filled data. Currently it's only working for textboxes or boolean. Seems that default values get overridden by pre-filled data.

survey.data = {feel: ["desparate"]}

What is the expected behavior?

If started with pre-filled data the data should be preferred to the default choice.

How would you reproduce the current behavior (if this is a bug)?

Create an survey with a checkbox and load it with data set.

Specify your

notz commented 4 years ago

Everything seems working if it's done after onAfterRenderSurvey event.

andrewtelnov commented 3 years ago

@notz You can assign the data at any time and it should work, unless you do not clear the survey.data. If you create a simple example in plunker that shows the issue then we can take a look to fix the issue for others. The simplest way to create the plunker example is to go to our examples, select "Edit in..." dropdown on the right top corner of the page and select plunker. After that in js file change the JSON and code.

Thank you, Andrew

notz commented 3 years ago

I only copied your get/set result sample to your survey creator and loaded your sample from there. It's not working anymore: https://plnkr.co/edit/Np1DqV5NTANxD0mi

andrewtelnov commented 3 years ago

@notz Got it. Survey overrides data when the survey JSON comes from our service and it happens after survey.data is set. The request to our service, as to any service, is async. You need to use survey.onLoadedSurveyFromService event. Here is the working example.

Thank you, Andrew