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

Cannot validate a column values using another survey question fix #6449 #6450

Merged
merged 1 commit into from
Jun 29, 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
8 changes: 7 additions & 1 deletion src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ implements ISurveyData, ISurveyImpl, ILocalizableOwner {
}
getFilteredValues(): any {
var allValues = this.getAllValues();
var values: { [key: string]: any } = { row: allValues };
var values: any = this.validationValues;
if(!values) values = {};
values.row = allValues;
for (var key in allValues) {
values[key] = allValues[key];
}
Expand Down Expand Up @@ -616,6 +618,7 @@ implements ISurveyData, ISurveyImpl, ILocalizableOwner {
this.detailPanel.readOnly = parentIsReadOnly;
}
}
private validationValues: any;
public hasErrors(
fireCallback: boolean,
rec: any,
Expand All @@ -624,6 +627,7 @@ implements ISurveyData, ISurveyImpl, ILocalizableOwner {
var res = false;
var cells = this.cells;
if (!cells) return res;
this.validationValues = rec.validationValues;
for (var colIndex = 0; colIndex < cells.length; colIndex++) {
if (!cells[colIndex]) continue;
var question = cells[colIndex].question;
Expand All @@ -646,6 +650,7 @@ implements ISurveyData, ISurveyImpl, ILocalizableOwner {
}
res = panelHasError || res;
}
this.validationValues = undefined;
return res;
}

Expand Down Expand Up @@ -1905,6 +1910,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
var res = false;
if (!rec) rec = {};
if (!rows) return rec;
rec.validationValues = this.getDataFilteredValues();
rec.isSingleDetailPanel = this.detailPanelMode === "underRowSingle";
for (var i = 0; i < rows.length; i++) {
res = rows[i].hasErrors(fireCallback, rec, () => {
Expand Down
33 changes: 33 additions & 0 deletions tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8224,4 +8224,37 @@ QUnit.test("matrixDragHandleArea = 'icon'", function (assert) {

nodeMock.classList.remove(matrix.cssClasses.dragElementDecorator);
assert.equal(matrix.isDragHandleAreaValid(nodeMock), true);
});
QUnit.test("column validation, bug#6449", function (assert) {
const survey = new SurveyModel({
elements: [
{
"type": "text",
"name": "age"
},
{
"type": "matrixdropdown",
"name": "matrix",
"columns": [
{
"name": "col1",
"cellType": "text",
"validators": [
{
"type": "expression",
"expression": "{row.col1} < {age}"
}
]
}
],
"rows": ["Row1"]
}] });
survey.setValue("age", 50);
const matrix = <QuestionMatrixDropdownModel>survey.getQuestionByName("matrix");
const cellQuestion = matrix.visibleRows[0].cells[0].question;
assert.equal(cellQuestion.name, "col1", "question is correct");
cellQuestion.value = 51;
assert.equal(survey.hasErrors(), true, "51<50");
cellQuestion.value = 41;
assert.equal(survey.hasErrors(), false, "41<50");
});