Skip to content

Commit

Permalink
#6625 Multiple-Choice Matrix with a Rating Scale column - The custom …
Browse files Browse the repository at this point in the history
…defined rate items aren't enabled by default (#6626)

Fixes #6625
  • Loading branch information
novikov82 committed Aug 1, 2023
1 parent f90a998 commit d038703
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -375,6 +377,7 @@ export class Base {

startLoadingFromJson(json?: any) {
this.isLoadingFromJsonValue = true;
this.jsonObj = json;
}
endLoadingFromJson() {
this.isLoadingFromJsonValue = false;
Expand Down
7 changes: 7 additions & 0 deletions src/question_matrixdropdowncolumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions src/question_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
53 changes: 53 additions & 0 deletions tests/question_ratingtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit d038703

Please sign in to comment.