Skip to content

Commit

Permalink
Single-Choice Matrix in Modern Theme - Rows receive the .sv-matrix__r…
Browse files Browse the repository at this point in the history
…ow--error class fix #7889
  • Loading branch information
andrewtelnov committed Feb 21, 2024
1 parent 6c2f13e commit 443768b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/question_matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export class QuestionMatrixModel
return loc ? loc : this.emptyLocalizableString;
}
supportGoNextPageAutomatic(): boolean {
return this.isMouseDown === true && this.hasValuesInAllRows();
return this.isMouseDown === true && this.hasValuesInAllRows(false);
}
private errorsInRow: HashTable<boolean>;
protected onCheckForErrors(errors: Array<SurveyError>, isOnValueChanged: boolean): void {
Expand All @@ -467,20 +467,20 @@ export class QuestionMatrixModel
}
}
private hasErrorAllRowsRequired(): boolean {
return this.isAllRowRequired && !this.hasValuesInAllRows();
return this.isAllRowRequired && !this.hasValuesInAllRows(true);
}
private hasErrorEachRowUnique(): boolean {
return this.eachRowUnique && this.hasNonUniqueValueInRow();
}
private hasValuesInAllRows(): boolean {
private hasValuesInAllRows(addError: boolean): boolean {
var rows = this.generatedVisibleRows;
if (!rows) rows = this.visibleRows;
if (!rows) return true;
let res = true;
for (var i = 0; i < rows.length; i++) {
const row = rows[i];
const hasValue = !this.isValueEmpty(row.value);
if(!hasValue) {
if(addError && !hasValue) {
this.addErrorIntoRow(row);
}
res = res && hasValue;
Expand Down Expand Up @@ -512,7 +512,7 @@ export class QuestionMatrixModel
this.errorsInRow[row.name] = true;
}
protected getIsAnswered(): boolean {
return super.getIsAnswered() && this.hasValuesInAllRows();
return super.getIsAnswered() && this.hasValuesInAllRows(false);
}
private createMatrixRow(
item: ItemValue,
Expand Down
24 changes: 24 additions & 0 deletions tests/question_matrix_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,30 @@ QUnit.test("matirix row, rowClasses property, eachRowUnique", function (assert)
assert.equal(question.hasErrorInRow(question.visibleRows[1]), false, "hasErrorInRow(1) #2");
assert.equal(question.visibleRows[1].rowClasses, "row", "second row #2");
});
QUnit.test("matirix row, rowClasses property, #7889", function (assert) {
const survey = new SurveyModel({
elements: [
{
type: "matrix",
name: "q1",
columns: ["col1", "col2"],
rows: ["row1", "row2", "row3"],
eachRowUnique: true,
},
],
});
survey.css = { matrix: { row: "row", rowError: "row_error" } };
const question = <QuestionMatrixModel>survey.getQuestionByName("q1");
assert.ok(question.cssClasses.row, "Row class is not empty");
assert.equal(question.hasErrorInRow(question.visibleRows[0]), false, "hasErrorInRow(0), #1");
assert.equal(question.hasErrorInRow(question.visibleRows[1]), false, "hasErrorInRow(1), #2");
assert.equal(question.hasErrorInRow(question.visibleRows[2]), false, "hasErrorInRow(2), #3");
question.visibleRows[0].cellClick(question.columns[0]);
assert.deepEqual(question.value, { row1: "col1" }, "value is set #4");
assert.equal(question.hasErrorInRow(question.visibleRows[0]), false, "hasErrorInRow(0), #5");
assert.equal(question.hasErrorInRow(question.visibleRows[1]), false, "hasErrorInRow(1), #6");
assert.equal(question.hasErrorInRow(question.visibleRows[2]), false, "hasErrorInRow(2), #7");
});
QUnit.test("check row randomization in design mode", (assert) => {

var json = {
Expand Down

0 comments on commit 443768b

Please sign in to comment.