Question T18405
Visible to All Users

[Object object] shown for dropdown option when the value is empty string ""

created 7 months ago

Hello Survey Team,

After updating to latest version 1.10.6, we encountered an issue with our dropdown. We use choicesByUrl to fetch the options of the dropdown and we use a default option with value "", but after the latest update we are observing [object Object] as Label and as value for that Default option (as shown in the screenshot).

Please check and let us know.

Thanks and regards.

Answers approved by surveyjs Support

created 7 months ago

Hello,
If you fetch choices from a server, you may not assign a non-existing value as a default value. Please implement the survey.onLoadChoicesFromServer event, retrieve a required option from a list, and set a question's defaultValue to the element's value.
Consider the following code:

JavaScript
survey.onLoadChoicesFromServer.add((sender, options) =>{ options.question.defaultValue = options.choices[0].value; })

View Demo

Let me know if you have further questions.

    Show previous comments (8)

      Hello,
      A follow-up: if you wish to allow users to reset a selected dropdown item, you can enable the Clear button (allowClear) and set a Dropdown's placeholder to 'Add a new family member'.

      JSON
      { "pages": [ { "name": "page1", "elements": [ { "type": "dropdown", "name": "question1", "choices": [ "Item 1", "Item 2", "Item 3" ], "placeholder": "Add a new family member" } ] } ] }

      Clipboard-File-1.png

      Let us know if you require further assistance.

      A A
      Ajuria - Forms Creation 7 months ago

        Hello Jane,
        Thank you for the suggestions.

        We went the other way to avoid empty string value. We added a value to the "Add a new family member" choicesByUrl response instead of the empty string. So now it is working correctly.

        Thanks and Regards.

          You're always welcome! Please feel free to contact us if you require further assistance.