diff --git a/src/base.ts b/src/base.ts index 17ce3f3786..0b9efef6f6 100644 --- a/src/base.ts +++ b/src/base.ts @@ -243,6 +243,8 @@ export class Base { }>; protected isLoadingFromJsonValue: boolean = false; public loadingOwner: Base = null; + + protected jsonObj: any; /** * An event that is raised when a property of this SurveyJS object has changed. * @@ -375,6 +377,7 @@ export class Base { startLoadingFromJson(json?: any) { this.isLoadingFromJsonValue = true; + this.jsonObj = json; } endLoadingFromJson() { this.isLoadingFromJsonValue = false; diff --git a/src/question_matrixdropdowncolumn.ts b/src/question_matrixdropdowncolumn.ts index 7e5fcc9110..e37200d77b 100644 --- a/src/question_matrixdropdowncolumn.ts +++ b/src/question_matrixdropdowncolumn.ts @@ -535,6 +535,13 @@ export class MatrixDropdownColumn extends Base delete json["choices"]; } delete json["itemComponent"]; + + if (this.jsonObj) { + Object.keys(this.jsonObj).forEach((prop) => { + json[prop] = this.jsonObj[prop]; + }); + } + new JsonObject().toObject(json, question); question.isContentElement = this.templateQuestion.isContentElement; this.previousChoicesId = undefined; diff --git a/src/question_rating.ts b/src/question_rating.ts index 5fdc8e5169..d9bf3b4f9c 100644 --- a/src/question_rating.ts +++ b/src/question_rating.ts @@ -88,18 +88,12 @@ export class QuestionRatingModel extends Question { ); this.initPropertyDependencies(); } - private jsonObj: any; private setIconsToRateValues() { if (this.rateType == "smileys") { this.rateValues.map(item => item.icon = this.getItemSmiley(item)); } } - startLoadingFromJson(jsonObj: any) { - super.startLoadingFromJson(jsonObj); - this.jsonObj = jsonObj; - } - endLoadingFromJson() { super.endLoadingFromJson(); this.initColors(); diff --git a/tests/question_ratingtests.ts b/tests/question_ratingtests.ts index 3da9a5cb2f..2a9ce5f660 100644 --- a/tests/question_ratingtests.ts +++ b/tests/question_ratingtests.ts @@ -1340,3 +1340,56 @@ QUnit.test("check rating triggerResponsiveness method", (assert) => { }, 1); }); + +QUnit.test("check rating in-matrix pre-defined items", (assert) => { + var json = { + logoPosition: "right", + pages: [ + { + name: "page1", + elements: [ + { + type: "matrixdropdown", + name: "q", + columns: [ + { + name: "Column 1", + cellType: "rating", + rateValues: [ + { + value: "item1", + text: "Rate Item 1" + }, + { + value: "item2", + text: "Rate Item 2" + }, + { + value: "item3", + text: "Rate Item 3" + }, + { + value: "item4", + text: "Rate Item 4" + }, + { + value: "item5", + text: "Rate Item 5" + } + ] + } + ], + choices: [1, 2, 3, 4, 5], + rows: ["Row 1", "Row 2"] + } + ] + } + ] + }; + const survey = new SurveyModel(json); + const q = survey.getQuestionByName("q") as QuestionMatrixDropdownModel; + var column = q.columns[0]; + assert.equal(column.templateQuestion.rateValues.length, 5); + assert.equal(column.templateQuestion.autoGenerate, false); + //assert.notOk(column.autoGenerate); +});