Issue T2055
Visible to All Users

Default value as Object

created 6 years ago (modified 6 years ago)

Hi guys, I have a problem with surveyjs about setting default value.
{
"pages": [
{
"name": "page1",
"elements": [
{
"type": "checkbox",
"name": "question1",
"defaultValue": [
{
"id": "2",
"test": "a2"
},
{
"id": "3",
"test": "a3"
}
],
"choices": [
{
"value": {
"id": "1",
"test": "a1"
},
"text": "a1"
},
{
"value": {
"id": "2",
"test": "a2"
},
"text": "a2"
},
{
"value": {
"id": "3",
"test": "a3"
},
"text": "a3"
}
]
}
]
}
]
}

As you see my definition above, the value that I set for the choices is an object.
And it's not working correctly.
The default value didn't set in UI. But that default value will be return in the result if I do not choose any options.
So I think that the default value that I set for the element still match with the choices, but somehow it's not showing in the UI.
And with my case, I really need to set the value is an object.
Can you guys help me check about that?
Thank you.

Comments (1)

    Hello,
    We did not test the default value with the complex objects.
    I will take a look.

    Thank you,
    Andrew
    SurveyJS Team

    Answers approved by surveyjs Support

    created 6 years ago

    Hello,

    Yes this was a bug related to choices by url. I've fixed it via the https://github.com/surveyjs/survey-library/commit/71e7efa3b0ecde3e229dfdf320a52acf9a0f1ea5 commit. Fix will be available in the nearest update.

    Thanks, Serge
    SurveyJS Team

      Show previous comments (5)

        Yes, I see. It would be hard to implement, but we will try. The issue that when you are setting the data the choices are not here and it is not defaultValue that we can try to set again on loading choices from the web. We will take a look on this week.

        Thank you,
        Andrew
        SurveyJS Team

          Thank you, please inform to me when it's fixed.

            Hello again,
            Fixed via this commit.

            Thank you,
            Andrew
            SurveyJS Team

            created 6 years ago

            I've fixed the issue for all "select base" class descendants. Fix will be available in the next minor update.

            Thanks, Serge
            SurveyJS Team

              created 6 years ago

              Hello,

              We've fixed the issue via the https://github.com/surveyjs/survey-library/commit/1c53e105717de60ba0f52cfc90ba767a4383b7fb and https://github.com/surveyjs/survey-library/commit/d8f13f7a6e36a3077df306f30fb7b35bf3bc2179 commits.
              Fix will be available in the nearest update, most likely today.

              Thanks, Serge
              SurveyJS Team

                Comments (3)

                  Hi, thank you for your support. But you know it's not just on checkbox.
                  Dropdown, radio maybe have the same issue with default value.

                    Hello,

                    Probably yes. I'll fix related issues with other questions.

                    Thanks, Serge
                    SurveyJS Team

                      That's really great.
                      Thank you.

                      Other Answers

                      created 6 years ago

                      Hi, thank you for supporting.
                      I have an issue related to the issue in this topic.
                      {
                      "pages": [
                      {
                      "name": "page1",
                      "elements": [
                      {
                      "type": "radigroup",
                      "name": "test",
                      "defaultValue":
                      {
                      "id": 1023
                      },
                      "choicesByUrl": {
                      "url": "https://orient-online-sh-1522994299711.firebaseio.com/test.json",
                      "valueName": "identity",
                      "titleName": "localizedData.id"
                      }
                      }
                      ]
                      }
                      ]
                      }

                      Here is my json.
                      The default got the same problem with the issue in this topic. It's not set in the UI, but in the result if we didn't choose any option.
                      But with checkbox, I set the defaultValue is an array. And it works.
                      Radiogroup and dropdown didn't work in this case.
                      Thank you.

                        created 6 years ago

                        Hi, thank you for supporting.
                        But I have one more problem related to object comparation.
                        It's about choicesVisibleIf, choicesEnableIf with value is object.
                        Here is the example. Can you help me check this problem.
                        {
                        "pages": [
                        {
                        "name": "page1",
                        "elements": [
                        {
                        "type": "checkbox",
                        "name": "question1",
                        "choices": [
                        {
                        "value": {
                        "id": "item1"
                        },
                        "text": "item1"
                        },
                        {
                        "value": {
                        "id": "item2"
                        },
                        "text": "item2"
                        },
                        {
                        "value": {
                        "id": "item3"
                        },
                        "text": "item3"
                        }
                        ],
                        "choicesVisibleIf": "{car} contains {item}"
                        },
                        {
                        "type": "radiogroup",
                        "name": "car",
                        "choices": [
                        {
                        "value": {
                        "id": "item1"
                        },
                        "text": "item1"
                        },
                        {
                        "value": {
                        "id": "item2"
                        },
                        "text": "item2"
                        },
                        {
                        "value": {
                        "id": "item3"
                        },
                        "text": "item3"
                        }
                        ]
                        }
                        ]
                        }
                        ]
                        }

                        Thank you.

                          Comments (1)

                            Hello,

                            I've created a separate ticket on your behalf (T2079: Help with choicesVisibleIf property). It has been placed in our processing queue and will be answered shortly.