Question T9268
Visible to All Users

Impact on migrating V1 to V2

created 3 years ago (modified 3 years ago)

Hi,

I realized in V1, when we have dropdown question, if we put label same as value in "choices", the json is like

JSON
[ { "value": "1 year", "text": "1 year" }, { "value": "2 years", "text": "2 years" }, { "value": "3 years", "text": "3 years" } ]

but in V2, the json is like

JSON
[ "1 year", "2 years", "3 years" ]

I have some code like

JavaScript
const label = survey.getQuestionByName('...').choices.text

, if I migrate the library from v1 to v2, will this code get impact? will label be undefined?

Answers approved by surveyjs Support

created 3 years ago

Hello,
Please use the following code, to always serialize the text property:

JavaScript
Survey.settings.itemValueAlwaysSerializeText = true;

Thank you,
Andrew
SurveyJS Team

    Comments (3)

      what's the package version?
      I am using v1.9.24 now, and I cant find itemValueAlwaysSerializeText in the setting class.
      here's my code

      Code
      import {   SurveyCreatorComponent,   SurveyCreator,   StylesManager,   settings } from 'survey-creator-react'; // customize setting settings.jsonEditor.indentation = 2; settings.itemValueAlwaysSerializeText = true;

      it didnt work, the json is still like

      JSON
      { "logoPosition": "right", "pages": [ { "name": "page1", "elements": [ { "type": "checkbox", "name": "question1", "choices": [ "item1", "item2", "item3" ] } ] } ] }

        Hello Sharon,
        This settings are belong to Survey and located in the survey-core package:

        JavaScript
        import { settings as surveySettings } from "survey-core"; surveySettings.itemValueAlwaysSerializeText = true;

        Here is the working example.

        Thank you,
        Andrew
        SurveyJS Team

          Thanks.