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

Add this.panel into expression function context in panel dynamic ques… #6807

Merged
merged 1 commit into from
Aug 26, 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: 4 additions & 4 deletions src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@ implements ISurveyData, ISurveyImpl, ILocalizableOwner {
}
values[MatrixDropdownRowModelBase.IndexVariableName] = this.rowIndex;
values[MatrixDropdownRowModelBase.RowValueVariableName] = this.rowName;
if (!properties) properties = {};
properties[MatrixDropdownRowModelBase.RowVariableName] = this;
const newProps = Helpers.createCopy(properties);
newProps[MatrixDropdownRowModelBase.RowVariableName] = this;
for (var i = 0; i < this.cells.length; i++) {
values[MatrixDropdownRowModelBase.RowVariableName] = this.value;
this.cells[i].runCondition(values, properties);
this.cells[i].runCondition(values, newProps);
}
if (!!this.detailPanel) {
this.detailPanel.runCondition(values, properties);
this.detailPanel.runCondition(values, newProps);
}
}
public clearValue() {
Expand Down
14 changes: 8 additions & 6 deletions src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1518,14 +1518,16 @@ export class QuestionPanelDynamicModel extends Question
cachedValues[QuestionPanelDynamicItem.ParentItemVariableName] = (<any>this.parent).getValue();
}
for (var i = 0; i < this.panels.length; i++) {
var panelValues = this.getPanelItemData(this.panels[i].data);
const panel = this.panels[i];
var panelValues = this.getPanelItemData(panel.data);
//Should be unique for every panel due async expression support
var newValues = Helpers.createCopy(cachedValues);
newValues[
QuestionPanelDynamicItem.ItemVariableName.toLowerCase()
] = panelValues;
const newValues = Helpers.createCopy(cachedValues);
const panelName = QuestionPanelDynamicItem.ItemVariableName;
newValues[panelName] = panelValues;
newValues[QuestionPanelDynamicItem.IndexVariableName.toLowerCase()] = i;
this.panels[i].runCondition(newValues, properties);
const newProps = Helpers.createCopy(properties);
newProps[panelName] = panel;
panel.runCondition(newValues, newProps);
}
}
onAnyValueChanged(name: string) {
Expand Down
2 changes: 1 addition & 1 deletion tests/entries/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export * from "../surveyLocalizationTests"; //
export * from "../surveyquestiontests"; //
export * from "../question_matrixdynamictests";
export * from "../question_matrixdropdownbasetests";
export * from "../surveypaneldynamictests";
export * from "../question_paneldynamic_tests";
export * from "../surveyserializationtests"; //
export * from "../surveytests"; //
export * from "../surveyWindowTests"; //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6037,4 +6037,35 @@ QUnit.test("paneldynamic.removePanelUI & confirmActionAsync, #6736", function(as
assert.deepEqual(panel.value, [{ q1: 1 }, { q1: 3 }], "Row is deleted correctly");

settings.confirmActionAsync = prevAsync;
});
});
QUnit.test("panel property in custom function", function (assert) {
const panelCustomFunc = function (params: any) {
if(!this.panel) return "";
const q = this.panel.getQuestionByName(params[0]);
if(q && !q.isEmpty()) return q.value + q.value;
return "";
};
FunctionFactory.Instance.register("panelCustomFunc", panelCustomFunc);
const survey = new SurveyModel({
elements: [
{
type: "paneldynamic",
name: "panel1",
templateElements: [
{ name: "q1", type: "text" },
{
name: "q2",
type: "expression",
expression: "panelCustomFunc('q1')",
},
],
panelCount: 2,
},
],
});
const question = <QuestionPanelDynamicModel>survey.getQuestionByName("panel1");
const panel = question.panels[0];
panel.getQuestionByName("q1").value = "abc";
assert.equal(panel.getQuestionByName("q2").value, "abcabc", "Custom function with row property works correctly");
FunctionFactory.Instance.unregister("panelCustomFunc");
});
Loading