Skip to content

Commit 9c4afdb

Browse files
authored
There is a JavaScript error if acceptedTypes property in the file question setup as an array fix #10627 (#10628)
1 parent 76b1422 commit 9c4afdb

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

packages/survey-core/src/question_file.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -601,12 +601,18 @@ export class QuestionFileModel extends QuestionFileModelBase {
601601
res.push(...categoryTypes);
602602
}
603603
});
604-
const customTypes = this.acceptedTypes || "";
605-
customTypes.split(",").forEach(type => {
606-
if (type && res.indexOf(type) < 0) {
607-
res.push(type);
608-
}
609-
});
604+
const addTypes = (types: Array<string>) => {
605+
types.forEach(type => {
606+
if (type && res.indexOf(type) < 0) {
607+
res.push(type);
608+
}
609+
});
610+
};
611+
if (Array.isArray(this.acceptedTypes)) {
612+
addTypes(this.acceptedTypes);
613+
} else {
614+
addTypes((this.acceptedTypes || "").split(","));
615+
}
610616
return res.length > 0 ? res.join(",") : undefined;
611617
}
612618
/**

packages/survey-core/tests/questionFileTests.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,4 +2522,21 @@ QUnit.test("questionFile acceptedCategories property, Issue#10602", function (as
25222522
q4.acceptedCategories = ["archive"];
25232523
assert.deepEqual(q4.acceptedCategories, ["archive", "custom"], "q4 categories after setting archive category");
25242524
assert.equal(q4.acceptedTypes, ".doc,.txt", "q4 acceptedTypes after setting archive category");
2525+
});
2526+
QUnit.test("questionFile acceptedTypes property as an array, Bug#10627", function (assert) {
2527+
const survey = new SurveyModel({
2528+
elements: [
2529+
{ type: "file", name: "q1", acceptedCategories: ["document"], acceptedTypes: [".pdf", ".jpeg"] },
2530+
{ type: "file", name: "q2", acceptedTypes: [".pdf", ".jpeg"] }
2531+
]
2532+
});
2533+
const documentTypes = ".pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.rtf,.odt";
2534+
const q1 = survey.getQuestionByName("q1") as QuestionFileModel;
2535+
const q2 = survey.getQuestionByName("q2") as QuestionFileModel;
2536+
assert.equal(q1.renderedAcceptedTypes, documentTypes + ",.jpeg", "#1");
2537+
assert.equal(q2.renderedAcceptedTypes, ".pdf,.jpeg", "#2");
2538+
q2.acceptedTypes = <any>[".doc", ".txt"];
2539+
assert.deepEqual(q2.acceptedCategories, ["custom"], "q2 categories after setting acceptedTypes");
2540+
assert.deepEqual(q2.toJSON(), { name: "q2", acceptedTypes: [".doc", ".txt"] }, "q2 json");
2541+
assert.equal(q2.renderedAcceptedTypes, ".doc,.txt", "#4");
25252542
});

0 commit comments

Comments
 (0)