Skip to content

Commit

Permalink
Merge pull request #7625 from surveyjs/bug/7615-matrix-vertical-colum…
Browse files Browse the repository at this point in the history
…n-requried

Dropdown Matrix - When a column's Required If rule is configured, the…
  • Loading branch information
andrewtelnov authored Jan 4, 2024
2 parents 071a766 + f4c18e6 commit f67151f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<ng-template
[component]="{ name: question.getCellWrapperComponentName($any(cell)), data: { componentData: question.getCellWrapperComponentData($any(cell))} }">
<sv-ng-string [model]="cell.locTitle"></sv-ng-string>
<span *ngIf="!!cell.requiredText" [class]="question.cssClasses.cellRequiredText">{{ cell.requiredText }}</span>
<span *ngIf="isRequiredCell" [class]="question.cssClasses.cellRequiredText">{{ cell.requiredText }}</span>
</ng-template>
</ng-container>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export class MatrixDropdownCellComponent extends BaseAngular<Question> {
if(this.cell.hasQuestion) {
return this.cell.question;
}
if(!!this.cell.column) {
return this.cell.column;
}
return null as any;
}
public get row(): MatrixDropdownRowModelBase {
Expand Down Expand Up @@ -72,6 +75,9 @@ export class MatrixDropdownCellComponent extends BaseAngular<Question> {
return { width: this.cell.width, minWidth: this.cell.minWidth };
return null;
}
public get isRequiredCell(): boolean {
return !!this.cell.column && this.cell.column.isRenderedRequired;
}
ngAfterViewInit() {
if (!this.cell.hasQuestion || !this.question || !this.question.survey) return;
const el = this.cellContainer.nativeElement;
Expand Down
27 changes: 3 additions & 24 deletions src/question_matrixdropdownrendered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class QuestionMatrixDropdownRenderedCell {
public choiceIndex: number;
public isOtherChoice: boolean;
public matrix: QuestionMatrixDropdownModelBase;
public requiredText: string;
public isEmpty: boolean;
public colSpans: number = 1;
public panel: PanelModel;
Expand All @@ -42,6 +41,9 @@ export class QuestionMatrixDropdownRenderedCell {
public constructor() {
this.idValue = QuestionMatrixDropdownRenderedCell.counter++;
}
public get requiredText(): string {
return this.column && this.column.isRenderedRequired ? this.column.requiredText : undefined;
}
public get hasQuestion(): boolean {
return !!this.question && !this.isErrorsCell;
}
Expand Down Expand Up @@ -867,9 +869,6 @@ export class QuestionMatrixDropdownRenderedTable extends Base {
.append(hCell.className)
.append(this.cssClasses.rowTextCell)
.append(this.cssClasses.columnTitleCell).toString();
if (!choice) {
this.setRequriedToHeaderCell(column, hCell);
}
res.cells.push(hCell);
}
var rows = this.matrix.visibleRows;
Expand Down Expand Up @@ -1014,7 +1013,6 @@ export class QuestionMatrixDropdownRenderedTable extends Base {
cell: QuestionMatrixDropdownRenderedCell
) {
this.setHeaderCellWidth(column, cell);
this.setRequriedToHeaderCell(column, cell);
}
private setHeaderCellWidth(
column: MatrixDropdownColumn,
Expand All @@ -1023,25 +1021,6 @@ export class QuestionMatrixDropdownRenderedTable extends Base {
cell.minWidth = column != null ? this.matrix.getColumnWidth(column) : this.matrix.getRowTitleWidth();
cell.width = column != null ? column.width : this.matrix.getRowTitleWidth();
}
private setRequriedToHeaderCell(
column: MatrixDropdownColumn,
cell: QuestionMatrixDropdownRenderedCell
) {
if (!!column && column.isRequired && this.matrix.survey) {
cell.requiredText = this.matrix.survey.requiredText;
}
}
private createRemoveRowCell(
row: MatrixDropdownRowModelBase
): QuestionMatrixDropdownRenderedCell {
var res = new QuestionMatrixDropdownRenderedCell();
res.row = row;
res.isRemoveRow = this.canRemoveRow(row);
if (!!this.cssClasses.cell) {
res.className = this.cssClasses.cell;
}
return res;
}
private createTextCell(
locTitle: LocalizableString
): QuestionMatrixDropdownRenderedCell {
Expand Down
46 changes: 46 additions & 0 deletions testCafe/questions/matrixdropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,49 @@ frameworks.forEach(framework => {
});
});
});

const json2 = {
"focusFirstQuestionAutomatic": true,
"elements": [{
"type": "radiogroup",
"name": "question2",
"defaultValue": "Item1",
"choices": [
"Item1",
"Item2",
"Item3"
]
},
{
"type": "matrixdropdown",
"name": "question1",
"columns": [
{
"name": "Column 1",
"cellType": "text",
"requiredIf": "{question2} = 'Item1'"
}
],
"columnLayout": "vertical",
"rows": [
"Row 1",
"Row 2"
]
}]
};
frameworks.forEach(framework => {
fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
async t => {
await initSurvey(framework, json2);
}
);

test("Column requiredIf and vertical layout", async t => {
const requiredSpan = Selector("span").withExactText("*");
await t.expect(requiredSpan.exists).ok();
await t.pressKey("down");
await t.expect(requiredSpan.exists).notOk();
await t.pressKey("up");
await t.expect(requiredSpan.exists).ok();
});
});
5 changes: 3 additions & 2 deletions tests/question_matrixdropdownbasetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ QUnit.test("column cell css classes for vertical layout", function (assert) {

const matrix = <QuestionMatrixDropdownModelBase>survey.getQuestionByName("question1");
assert.equal(matrix.renderedTable.headerRow.cells.length, 3);
assert.equal(matrix.renderedTable.headerRow.cells[1].className, "sv_matrix_cell_header", "column 1");
assert.equal(matrix.renderedTable.headerRow.cells[2].className, "sv_matrix_cell_header", "column 2");
const cssHeader = survey.css.matrixdropdown.headerCell;
assert.equal(matrix.renderedTable.headerRow.cells[1].className, cssHeader, "column 1");
assert.equal(matrix.renderedTable.headerRow.cells[2].className, cssHeader, "column 2");
});

QUnit.test("column cell css classes by matrix cellType test", function (assert) {
Expand Down

0 comments on commit f67151f

Please sign in to comment.