Skip to content

Commit

Permalink
resetValueIf should work for invisible questions (#7057)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov authored Oct 2, 2023
1 parent 2e6cd87 commit fc68d07
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export class Question extends SurveyElement<Question>
private resetValueIfExpression: ExpressionRunner;
private isRunningResetValueIf: boolean;
public runTriggers(name: string, value: any): void {
if(this.isRunningResetValueIf || !this.isVisible || this.isReadOnly || !this.resetValueIf || this.isEmpty() || this.isSettingQuestionValue) return;
if(this.isRunningResetValueIf || this.isReadOnly || !this.resetValueIf || this.isEmpty() || this.isSettingQuestionValue) return;
if(this.parentQuestion && this.parentQuestion.getValueName() === name) return;
if(!this.resetValueIfExpression) {
this.resetValueIfExpression = new ExpressionRunner(this.resetValueIf);
Expand Down
2 changes: 1 addition & 1 deletion src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5686,7 +5686,7 @@ export class SurveyModel extends SurveyElementCore
}
private runQuestionsTriggers(name: string, value: any): void {
if(this.isDisplayMode || this.isDesignMode) return;
const questions = this.getAllQuestions(true);
const questions = this.getAllQuestions();
questions.forEach(q => q.runTriggers(name, value));
}
private checkIfNewPagesBecomeVisible(oldCurrentPageIndex: number) {
Expand Down
10 changes: 6 additions & 4 deletions tests/question_customtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,14 +981,15 @@ QUnit.test("Single: onAfterRender and onAfterRenderContentElement", function (
elements: [{ type: "newquestion", name: "q1" }],
});
var q = <QuestionCustomModel>survey.getAllQuestions()[0];
q.afterRender(5);
const el: HTMLElement = <any>({ a: 5 });
q.afterRender(el);
assert.equal(
afterRenderQuestion.name,
"q1",
"onAfterRender, question parameter is correct"
);
assert.equal(
afterRenderHtmlElement,
(<any>afterRenderHtmlElement).a,
5,
"onAfterRender, htmlElement parameter is correct"
);
Expand Down Expand Up @@ -1046,14 +1047,15 @@ QUnit.test("Composite: onAfterRender and onAfterRenderContentElement", function
elements: [{ type: "fullname", name: "q1" }],
});
var q = <QuestionCompositeModel>survey.getAllQuestions()[0];
q.afterRender(5);
const el: HTMLElement = <any>({ a: 5 });
q.afterRender(el);
assert.equal(
afterRenderQuestion.name,
"q1",
"onAfterRender, question parameter is correct"
);
assert.equal(
afterRenderHtmlElement,
(<any>afterRenderHtmlElement).a,
5,
"onAfterRender, htmlElement parameter is correct"
);
Expand Down
21 changes: 21 additions & 0 deletions tests/surveyquestiontests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7325,6 +7325,27 @@ QUnit.test("question.resetValueIf, cycle calls", function (assert) {
assert.equal(q3.isEmpty(), true, "q2.value #3");
assert.equal(q3.isEmpty(), true, "q3.value #3");
});
QUnit.test("question.resetValueIf and invisibleQuestions", function (assert) {
const survey = new SurveyModel({
elements: [{
"name": "q1",
"type": "text"
},
{
"name": "q2",
"type": "text",
"resetValueIf": "{q1} = 1",
"visible": false
}
] });
const q1 = survey.getQuestionByName("q1");
const q2 = survey.getQuestionByName("q2");
q2.value = "abc";
assert.equal(q2.value, "abc", "value is set");
q1.value = 1;
assert.equal(q2.isEmpty(), true, "value is cleared");
});

QUnit.test("question.isReady & async functions in expression", function (assert) {
var returnResult1: (res: any) => void;
var returnResult2: (res: any) => void;
Expand Down

0 comments on commit fc68d07

Please sign in to comment.