Skip to content

Commit

Permalink
Progress Bar counts invisible questions when calculating the total pr…
Browse files Browse the repository at this point in the history
…ogress value #8514
  • Loading branch information
andrewtelnov committed Jul 9, 2024
1 parent e060a2e commit 60eb5cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1925,9 +1925,10 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
for (var i = 0; i < this.columns.length; i++) {
const col = this.columns[i];
if (!col.templateQuestion.hasInput) continue;
const hasValue = !Helpers.isValueEmpty(rowValue[col.name]);
if(!hasValue && !!col.templateQuestion.visibleIf) continue;
res.questionCount += 1;
res.requiredQuestionCount += col.isRequired;
const hasValue = !Helpers.isValueEmpty(rowValue[col.name]);
res.answeredQuestionCount += hasValue ? 1 : 0;
res.requiredAnsweredQuestionCount += hasValue && col.isRequired ? 1 : 0;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,30 @@ QUnit.test("progressText, 'requiredQuestions' type and design mode", function (
assert.equal(survey.getProgressTypeComponent(), "sv-progress-requiredquestions", "requiredQuestions component");
assert.equal(survey.progressText, "Answered 0/2 questions");
});
QUnit.test("progressText, 'questions' type, invisible cells and data", function (
assert
) {
var survey = new SurveyModel({
progressBarType: "questions",
elements: [
{ type: "matrixdynamic", name: "matrix",
columns: [
{ cellType: "text", name: "col1" },
{ cellType: "boolean", name: "col2" },
{ cellType: "text", name: "col3", visibleIf: "{row.col2}=true" },
]
}
]
});
survey.data = { matrix: [{ col1: "abc1", col2: true, col3: "edf1" }, { col1: "abc1", col2: false }] };
assert.equal(survey.progressText, "Answered 5/5 questions", "#1");
const matrix = survey.getQuestionByName("matrix");
const rows = matrix.visibleRows;
rows[1].getQuestionByName("col2").value = true;
assert.equal(survey.progressText, "Answered 5/6 questions", "#2");
rows[1].getQuestionByName("col3").value = "abc";
assert.equal(survey.progressText, "Answered 6/6 questions", "#3");
});
QUnit.test("progressText, 'requiredQuestions' type and required matrix dropdown, bug#5375", function (
assert
) {
Expand Down

0 comments on commit 60eb5cd

Please sign in to comment.