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

resetValueIf should work for invisible questions #7057

Merged
merged 1 commit into from
Oct 2, 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
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