Question T12976
Visible to All Users

itemvalues default values not saved

created 2 years ago

Good morning,

I added an itemvalues property to the survey creator but the default values are not saved to the survey's definition.
It's only after making the first change to that property that it shows in the JSON.

Here is the code I've been using:

Code
const defaultChoices = [   { value: 'grp1', text: 'Groupe 1' },   { value: 'grp2', text: 'Groupe 2' },   { value: 'grp3', text: 'Groupe 3' }, ]; Serializer.addProperty('survey', {   name: 'scenarios:itemvalues',   category: myCategory,   displayName: scenarios,   default: defaultChoices,   choices: defaultChoices, });

As you can see in the following image, the array of values does show in the creator.survey.scenarios but not in the creator JSON triggered on auto save.
Clipboard-File-1.png

Is there a method or a specific propertyInfo structure I could use to save default values in the definition?

PS: I do have the commercial license.

Answers approved by surveyjs Support

created 2 years ago

Hello Gregoire,
We do not serialize the default value into JSON, otherwise JSON would be huge. It is a designed behavior.
Since this property in the survey model, then the best way to handle this situation is to set this property on creating a new survey.
When you create a new survey, instead of setting creator.JSON = {}; you can set it as:

JavaScript
const initialSurveyJSON = { scenarios: [ { value: 'grp1', text: 'Groupe 1' }, { value: 'grp2', text: 'Groupe 2' }, { value: 'grp3', text: 'Groupe 3' }, ] }; creator.JSON = initialSurveyJSON;

You will need to remove the default attribute from your property declaration. Otherwise, your property will not saved anyway.

Thank you,
Andrew
SurveyJS Team