Skip to content

Commit 224dfd8

Browse files
authored
Panel visibility doesn't work correctly if expression checks the element properties fix #11126 (#11128)
1 parent 65e14c8 commit 224dfd8

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

packages/survey-core/src/panel.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { SurveyError } from "./survey-error";
3030
import { CssClassBuilder } from "./utils/cssClassBuilder";
3131
import { IAction } from "./actions/action";
3232
import { ActionContainer } from "./actions/container";
33+
import { IValueGetterContext } from "./conditions/conditionProcessValue";
3334
import { SurveyModel } from "./survey";
3435
import { AnimationGroup, IAnimationGroupConsumer } from "./utils/animation";
3536
import { DomDocumentHelper, DomWindowHelper } from "./global_variables_utils";
@@ -413,6 +414,18 @@ export class PanelModelBase extends SurveyElement<Question>
413414
public getType(): string {
414415
return "panelbase";
415416
}
417+
public getValueGetterContext(): IValueGetterContext {
418+
const ctx = super.getValueGetterContext();
419+
if (!ctx) return ctx;
420+
const self = this;
421+
return {
422+
getValue: (params) => ctx.getValue(params),
423+
getTextValue: ctx.getTextValue ? (name, value, isDisplayValue) => ctx.getTextValue(name, value, isDisplayValue) : undefined,
424+
getObj: () => self,
425+
getRootObj: ctx.getRootObj ? () => ctx.getRootObj() : undefined,
426+
getQuestion: ctx.getQuestion ? () => ctx.getQuestion() : undefined
427+
};
428+
}
416429
public setSurveyImpl(value: ISurveyImpl, isLight?: boolean): void {
417430
//if(this.surveyImpl === value) return; TODO refactor
418431
this.blockAnimations();

packages/survey-core/tests/surveytests.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23319,3 +23319,57 @@ QUnit.test("Re-run expressions on changing the related object properties, Bug#10
2331923319
assert.equal(q2.visible, true, "q2 is visible after locale change to ''");
2332023320
assert.equal(q3.visibleChoices.length, 2, "q3 has two visible choices after locale change to ''");
2332123321
});
23322+
QUnit.test("visibleIf with $q.containsErrors and checkErrorsMode=onValueChanged", function (assert) {
23323+
const survey = new SurveyModel({
23324+
checkErrorsMode: "onValueChanged",
23325+
elements: [
23326+
{
23327+
type: "text",
23328+
name: "q1",
23329+
inputType: "number",
23330+
min: 10
23331+
},
23332+
{
23333+
type: "text",
23334+
name: "q2",
23335+
visibleIf: "{q1} notempty and {$q1.containsErrors} = false"
23336+
}
23337+
]
23338+
});
23339+
const q1 = survey.getQuestionByName("q1");
23340+
const q2 = survey.getQuestionByName("q2");
23341+
assert.equal(q2.isVisible, false, "q2 is invisible initially, q1 is empty");
23342+
q1.value = 20;
23343+
assert.equal(q1.errors.length, 0, "q1 has no errors, value=20 >= min=10");
23344+
assert.equal(q2.isVisible, true, "q2 is visible, q1=20 and no errors");
23345+
q1.value = 5;
23346+
assert.equal(q1.errors.length, 1, "q1 has error, value=5 < min=10");
23347+
assert.equal(q2.isVisible, false, "q2 is invisible, q1=5 contains errors");
23348+
}); QUnit.test("Panel visibleIf with $q.containsErrors and checkErrorsMode=onValueChanged", function (assert) {
23349+
const survey = new SurveyModel({
23350+
checkErrorsMode: "onValueChanged",
23351+
elements: [
23352+
{
23353+
type: "text",
23354+
name: "q1",
23355+
inputType: "number",
23356+
min: 10
23357+
},
23358+
{
23359+
type: "panel",
23360+
name: "panel1",
23361+
visibleIf: "{q1} notempty and {$q1.containsErrors} = false",
23362+
elements: [{ type: "text", name: "q2" }]
23363+
}
23364+
]
23365+
});
23366+
const q1 = survey.getQuestionByName("q1");
23367+
const panel1 = survey.getPanelByName("panel1");
23368+
assert.equal(panel1.isVisible, false, "panel1 is invisible initially, q1 is empty");
23369+
q1.value = 20;
23370+
assert.equal(q1.errors.length, 0, "q1 has no errors, value=20 >= min=10");
23371+
assert.equal(panel1.isVisible, true, "panel1 is visible, q1=20 and no errors");
23372+
q1.value = 5;
23373+
assert.equal(q1.errors.length, 1, "q1 has error, value=5 < min=10");
23374+
assert.equal(panel1.isVisible, false, "panel1 is invisible, q1=5 contains errors");
23375+
});

0 commit comments

Comments
 (0)