Skip to content

Commit

Permalink
survey.mergeData function fix #6197 (#6203)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov authored May 16, 2023
1 parent a6c2733 commit 77ff467
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function mergeValues(src: any, dest: any) {
if (typeof dest !== "object") return;
for (var key in src) {
var value = src[key];
if (value && typeof value === "object") {
if (!Array.isArray(value) && value && typeof value === "object") {
if (!dest[key] || typeof dest[key] !== "object") dest[key] = {};
mergeValues(value, dest[key]);
} else {
Expand Down
23 changes: 23 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PanelModel } from "../src/panel";
import { QuestionFactory } from "../src/questionfactory";
import { Question } from "../src/question";
import { QuestionHtmlModel } from "../src/question_html";
import { QuestionImageModel } from "../src/question_image";
import {
SurveyTriggerVisible,
SurveyTriggerComplete,
Expand Down Expand Up @@ -100,6 +101,28 @@ QUnit.test("merge data property", function (assert) {
"do nothing"
);
});
QUnit.test("merge data for image question", function (assert) {
const survey = new SurveyModel({
elements: [
{
type: "file",
"name": "image",
"showPreview": true
}
]
});
const imageData = [
{
name: "maxresdefault.jpg",
type: "image/jpeg",
content:
"data:image/jpeg;base64,=123test"
}
];
survey.mergeData({ image: imageData });
const question = <QuestionImageModel>survey.getQuestionByName("image");
assert.deepEqual(question.value, imageData, "value set correctly");
});
QUnit.test("Add two pages", function (assert) {
var survey = new SurveyModel();
survey.addPage(new PageModel("Page 1"));
Expand Down

0 comments on commit 77ff467

Please sign in to comment.