Closed yellow-sunshine closed 10 months ago
Hello @yellow-sunshine, Different SurveyJS questions have different value format. Dynamic Matrices receive an array of objects of the following structure:
[
{
columnName1: val1,
columnNameX: valX
},
{
columnName1: val1,
columnNameX: valX
}
]
For the record: you can review the format of question values in the question.value property description.
If you wish to programmatically populate matrix row values, you can use the survey.setValue function as follows:
survey.setValue("licenses", [
{
license_authority: "EPA",
license_number: "EPA43459254",
license_date: "2023-05-10",
status: "Yes"
}
]);
To populate multiple question values, you can use the survey.data
/ survey.mergeData()
API:
survey.data = {
name: "Yellow Sunshine",
licenses: [
{
license_authority: "EPA",
license_number: "EPA43459254",
license_date: "2023-05-10",
status: "Yes"
}
]
};
For more information on how to populate question values, refer to the following guide: Populate Form Fields.
Should you have any further questions or require assistance, we are here to help.
Are you requesting a feature, reporting a bug or asking a question?
Bug, maybe a failure of my understanding which would turn this into a Question
What is the current behavior?
I am pulling data from a database and populating the survey with values. In my example, I am only trying to add one row to a matrixdynamic by hard coding it instead of getting it from DB. It adds a blank row to the matrixdynamic resulting in two rows each without data. Running setValue() on other text fields works as intended. The survey also does not load at the first question on the first page, it skips straight to the matrixdynamic on the second page where the row is added.
What is the expected behavior?
Each time I call addrow(), it should add a row to the matrixdynamic with the passed json data. The first "addrow()" performed should actually not add a row but it should fill out the current row that exists by default. It should not automatically go to the page where the row was added.
How would you reproduce the current behavior (if this is a bug)?
As a programmer: Create a survey with a matrixdynamic on the second page. Once the survey is created, add a row. As a user: just load the survey.
Provide the test code and the tested page URL (if applicable)
Tested page URL: https://www.brentrussell.com/projects/surveyjs-demo/
Test code You can view the source of the test page URL or read here:
surveyjson.json:
Specify your