Skip to content

Commit

Permalink
Fix error on deserializing column rating
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Oct 13, 2023
1 parent cb0ade3 commit 9e18cdd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/question_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,11 @@ Serializer.addClass(
visibleIndex: 20
},
{ name: "itemComponent", visible: false,
defaultFunc: (obj: any): any => { return !!obj ? obj.getDefaultItemComponent(): "sv-rating-item"; } }
defaultFunc: (obj: any): any => {
if(!obj) return "sv-rating-item";
if(!!obj.getOriginalObj) obj = obj.getOriginalObj();
return obj.getDefaultItemComponent();
} }
],
function () {
return new QuestionRatingModel("");
Expand Down
15 changes: 15 additions & 0 deletions tests/question_ratingtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1490,4 +1490,19 @@ QUnit.test("Generate empty rating", (assert) => {
q1.rateType = "stars";
assert.deepEqual(q1.toJSON(), { name: "q1", rateType: "stars" });
q1.rateType = "stars";
});
QUnit.test("Generate empty rating in column", (assert) => {
const q1 = new QuestionMatrixDropdownModel("q1");
const col1: any = q1.addColumn("col1");
col1.cellType = "rating";
const col2: any = q1.addColumn("col2");
col2.cellType = "rating";
col2.rateType = "stars";
assert.deepEqual(q1.toJSON(), { name: "q1",
columns: [
{ name: "col1", cellType: "rating" },
{ name: "col2", cellType: "rating", rateType: "stars" }
] });
assert.equal(col1.itemComponent, "sv-rating-item");
assert.equal(col2.itemComponent, "sv-rating-item-star");
});

0 comments on commit 9e18cdd

Please sign in to comment.