Skip to content

Commit

Permalink
The valuePropertyName doesn't work in a Dynamic Matrix fix #7605
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Dec 29, 2023
1 parent 1f597d5 commit 9a93052
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SurveyError } from "./survey-error";
import { CssClassBuilder } from "./utils/cssClassBuilder";
import { IMatrixColumnOwner, MatrixDropdownColumn } from "./question_matrixdropdowncolumn";
import { QuestionMatrixDropdownRenderedCell, QuestionMatrixDropdownRenderedRow, QuestionMatrixDropdownRenderedTable } from "./question_matrixdropdownrendered";
import { mergeValues } from "./utils/utils";

export interface IMatrixDropdownData {
value: any;
Expand Down Expand Up @@ -371,23 +372,28 @@ implements ISurveyData, ISurveyImpl, ILocalizableOwner {
getFilteredProperties(): any {
return { survey: this.getSurvey(), row: this };
}
public runCondition(values: HashTable<any>, properties: HashTable<any>) {
public runCondition(values: HashTable<any>, properties: HashTable<any>): void {
if (!!this.data) {
values[MatrixDropdownRowModelBase.OwnerVariableName] = this.data.value;
}
values[MatrixDropdownRowModelBase.IndexVariableName] = this.rowIndex;
const rowIndex = this.rowIndex;
values[MatrixDropdownRowModelBase.IndexVariableName] = rowIndex;
values[MatrixDropdownRowModelBase.RowValueVariableName] = this.rowName;
const newProps = Helpers.createCopy(properties);
newProps[MatrixDropdownRowModelBase.RowVariableName] = this;
const rowValues = rowIndex > 0 ? this.data.getRowValue(this.rowIndex - 1) : this.value;
for (var i = 0; i < this.cells.length; i++) {
values[MatrixDropdownRowModelBase.RowVariableName] = this.value;
if(i > 0) {
mergeValues(this.value, rowValues);
}
values[MatrixDropdownRowModelBase.RowVariableName] = rowValues;
this.cells[i].runCondition(values, newProps);
}
if (!!this.detailPanel) {
this.detailPanel.runCondition(values, newProps);
}
}
public clearValue() {
public clearValue(): void {
var questions = this.questions;
for (var i = 0; i < questions.length; i++) {
questions[i].clearValue();
Expand Down
38 changes: 38 additions & 0 deletions tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9015,3 +9015,41 @@ QUnit.test("matrix dynamic getPlainData & comment", function (assert) {
assert.equal(qData[2].title, "Comment", "comment title");
assert.equal(qData[2].isComment, true, "comment isComment");
});
QUnit.test("matrix dynamic expression & checkbox ValuePropertyName", function (assert) {
const survey = new SurveyModel({
"elements": [
{
"type": "checkbox",
"name": "q1",
"choices": [
"Item 1",
"Item 2"
],
"valuePropertyName": "testItem"
},
{
"type": "matrixdynamic",
"name": "q2",
"valueName": "q1",
"columns": [
{
"name": "col1",
"cellType": "expression",
"expression": "{row.testItem} + ' - matrix'"
}
],
"rowCount": 0
}
]
});
const checkbox = <QuestionCheckboxModel>survey.getQuestionByName("q1");
const matrix = <QuestionMatrixDynamicModel>survey.getQuestionByName("q2");
assert.notOk(matrix.value, "matrix is empty");
checkbox.renderedValue = ["Item 1"];
assert.equal(matrix.visibleRows.length, 1, "matrix rows #1");
assert.deepEqual(matrix.value, [{ testItem: "Item 1", col1: "Item 1 - matrix" }], "matrix value #1");
checkbox.renderedValue = ["Item 1", "Item 2"];
assert.equal(matrix.visibleRows.length, 2, "matrix rows #2");
assert.deepEqual(matrix.value, [{ testItem: "Item 1", col1: "Item 1 - matrix" }, { testItem: "Item 2", col1: "Item 2 - matrix" }], "matrix value #2");
});

0 comments on commit 9a93052

Please sign in to comment.