Question T7853
Visible to All Users

Initialize survey question with multiple choices

created 4 years ago

Hello,

I want to initialize a survey result using question of type checkbox with a flat JSON ( without arrays ) ,

example:1 ( question 1 of type checkbox )

JSON
{ "question1":"item1"}

example:2 ( question 2 of type checkbox )

JSON
{ "question2":"item1,item2"}

the current behavior of SurveyJS: he acceptOnly the following structure { "question1":["item1","item2"]},
if no array is provided to initialize the questions, survey result is displayed without initialized answers

Note: i dont have hands to change the incoming structure. is there any solution survey designer side ?

Regards,
Dhia

Answers approved by surveyjs Support

created 4 years ago

Hello,
SurveyJS requires an array for array value, based on JSON standard.
You can write a converter from array to string and from string to array.
If a question "getType()" function returns "checkbox", then you will have to call a converter when needed. SurveyJS will provide you a correct JSON and if you want to set it back, then you have to provide the correct JSON as well.
However, I would suggest to add a display text attribute to your JSON and convert an array into string in one way.

Thank you,
Andrew
SurveyJS Team