Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed https://github.com/surveyjs/survey-creator/issues/3916 - 'Apply' button in Edit Totals popup causes console error 'Cannot read properties of null #5912

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2305,10 +2305,10 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
return this.SurveyModel.getMatrixCellTemplateData(cell);
}
public getCellWrapperComponentName(cell: MatrixDropdownCell) {
return this.SurveyModel.getElementWrapperComponentName(cell, "cell");
return this.SurveyModel.getElementWrapperComponentName(cell, cell.row instanceof MatrixDropdownTotalRowModel ? "row-footer" : "cell");
}
public getCellWrapperComponentData(cell: MatrixDropdownCell) {
return this.SurveyModel.getElementWrapperComponentData(cell, "cell");
return this.SurveyModel.getElementWrapperComponentData(cell, cell.row instanceof MatrixDropdownTotalRowModel ? "row-footer" : "cell");
}
public getColumnHeaderWrapperComponentName(cell: MatrixDropdownCell) {
return this.SurveyModel.getElementWrapperComponentName(
Expand Down
2 changes: 1 addition & 1 deletion src/react/reactquestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export class SurveyQuestionAndErrorsCell extends SurveyQuestionAndErrorsWrapped
const survey: SurveyModel = this.question.survey as SurveyModel;
let wrapper: JSX.Element | null = null;
if (survey) {
wrapper = ReactSurveyElementsWrapper.wrapMatrixCell(survey, element, cell);
wrapper = ReactSurveyElementsWrapper.wrapMatrixCell(survey, element, cell, this.props.reason);
}
return wrapper ?? element;
}
Expand Down
19 changes: 13 additions & 6 deletions src/react/reactquestion_matrixdropdownbase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ export class SurveyQuestionMatrixDropdownBase extends SurveyQuestionElementBase
var row = this.renderRow(
"footer",
table.footerRow,
this.question.cssClasses
this.question.cssClasses,
"row-footer"
);
return <tfoot>{row}</tfoot>;
}
Expand All @@ -131,13 +132,14 @@ export class SurveyQuestionMatrixDropdownBase extends SurveyQuestionElementBase
renderRow(
keyValue: any,
row: QuestionMatrixDropdownRenderedRow,
cssClasses: any
cssClasses: any,
reason?: string
): JSX.Element {
var matrixrow:Array<JSX.Element> = [];
var cells = row.cells;

for (var i = 0; i < cells.length; i++) {
matrixrow.push(this.renderCell(cells[i], i, cssClasses));
matrixrow.push(this.renderCell(cells[i], i, cssClasses, reason));
}
var key = "row" + keyValue;

Expand All @@ -151,7 +153,8 @@ export class SurveyQuestionMatrixDropdownBase extends SurveyQuestionElementBase
renderCell(
cell: QuestionMatrixDropdownRenderedCell,
index: number,
cssClasses: any
cssClasses: any,
reason?: string
): JSX.Element {
var key = "cell" + index;
if (cell.hasQuestion) {
Expand All @@ -161,11 +164,15 @@ export class SurveyQuestionMatrixDropdownBase extends SurveyQuestionElementBase
cssClasses={cssClasses}
cell={cell}
creator={this.creator}
reason={reason}
/>
);
}
let reason = cell.hasTitle ? "row-header" : "";
var cellContent = this.renderCellContent(cell, reason, cssClasses);
let calcReason = reason;
if(!calcReason) {
calcReason = cell.hasTitle ? "row-header" : "";
}
var cellContent = this.renderCellContent(cell, calcReason, cssClasses);
var cellStyle: any = null;
if (!!cell.width || !!cell.minWidth) {
cellStyle = {};
Expand Down
51 changes: 50 additions & 1 deletion tests/question_matrixdropdownbasetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,53 @@ QUnit.test("Check matrixdropdown cells cssClasses with showInMultipleColumns", f
assert.equal(columnName, "col1", "The event raised correctly");
matrix.columns.push(new MatrixDropdownColumn("col2"));
assert.equal(columnName, "col2", "The event raised correctly on adding into array");
});
});

class TestElementWrapperSurveyModel extends SurveyModel {
constructor(json: any) {
super(json);
}
public getElementWrapperComponentName(element: any, reason?: string): string {
this.reason = "name->" + reason;
return super.getElementWrapperComponentName(element, reason);
}
public getElementWrapperComponentData(element: any, reason?: string): string {
this.reason = "data->" + reason;
return super.getElementWrapperComponentData(element, reason);
}
public reason?: string;
}

QUnit.test("getCellWrapper name and data", function (assert) {
var json = {
elements: [
{
type: "matrixdynamic",
name: "q1",
columns: [
{
name: "Column 1",
totalType: "sum",
},
],
rows: ["First"]
},
],
};
var survey = new TestElementWrapperSurveyModel(json);
var matrix = <QuestionMatrixDropdownModelBase>survey.getQuestionByName("q1");

var totalRow = matrix.visibleTotalRow;
var totalCell = totalRow.cells[0];
matrix.getCellWrapperComponentName(totalCell);
assert.equal(survey.reason, "name->row-footer", "Total cell component name");
matrix.getCellWrapperComponentData(totalCell);
assert.equal(survey.reason, "data->row-footer", "Total cell component data");

var ordinaryRow = matrix.visibleRows[0];
var ordinaryCell = ordinaryRow.cells[0];
matrix.getCellWrapperComponentName(ordinaryCell);
assert.equal(survey.reason, "name->cell", "Ordinary cell component name");
matrix.getCellWrapperComponentData(ordinaryCell);
assert.equal(survey.reason, "data->cell", "Ordinary cell component data");
});