surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.12k stars 802 forks source link

Dropdown default values overriding the edit mode values. #8352

Closed missakation closed 3 months ago

missakation commented 3 months ago

Are you requesting a feature, reporting a bug or asking a question?

Reporting a bug

What is the current behavior?

When I have a dropdown with a default value and I open the form and populate it with an existing data, the default values always override the data that I provide

What is the expected behavior?

Form should not override the data that I provide.

How would you reproduce the current behavior (if this is a bug)?

First we define the dropdown

      {
       "type": "dropdown",
       "name": "country",
       "title": "Country",
       "hideNumber": true,
       "defaultValue": "CANADA",
       "isRequired": true,
       "choices": [
        {
         "value": "UNITED STATES",
         "text": "United States"
        },
        {
         "value": "CANADA",
         "text": "Canada"
        }
       ]
      },

and in node.js when I provide the data as default values(This is used when editing)

_survey.data = {
    country: "UNITED STATUES
};

It always picks the Canada because that's the default value.

andrewtelnov commented 3 months ago

@missakation You misspelled the country name on setting the data. Here is the working example.

Thank you, Andrew

missakation commented 3 months ago

@missakation You misspelled the country name on setting the data. Here is the working example.

Thank you, Andrew

Actually I am loading the form like

const _survey = new Model({
  surveyId: "a873d8ee...",
  surveyPostId: "7b341277-...",
});

Spelling mistake was my bad. I am using the correct value in my project. Maybe loading the from via API is causing this.