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

! operator with async expressions causes error fix #7268 #7272

Merged
merged 2 commits into from
Nov 1, 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
10 changes: 9 additions & 1 deletion src/expressions/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,19 @@ export class UnaryOperand extends Operand {
const uOp = <UnaryOperand>op;
return uOp.operator == this.operator && this.areOperatorsEquals(this.expression, uOp.expression);
}
public hasFunction(): boolean {
return this.expression.hasFunction();
}
public hasAsyncFunction(): boolean {
return this.expression.hasAsyncFunction();
}
public addToAsyncList(list: Array<FunctionOperand>): void {
this.expression.addToAsyncList(list);
}
public evaluate(processValue?: ProcessValue): boolean {
let value = this.expression.evaluate(processValue);
return this.consumer.call(this, value);
}

public setVariables(variables: Array<string>) {
this.expression.setVariables(variables);
}
Expand Down
28 changes: 28 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13748,6 +13748,34 @@ QUnit.test(
SurveyElement.FocusElement = oldFunc;
}
);
QUnit.test("Async function with negative result, Bug#7268",
function (assert) {
let returnResult: (res: any) => void = (res: any): void => {
res = false;
};
function asyncFunc(params: any): any {
returnResult = this.returnResult;
return false;
}
FunctionFactory.Instance.register("asyncFunc", asyncFunc, true);
const survey = new SurveyModel({
elements: [
{ type: "text", name: "q1", isRequired: true },
{
type: "text", name: "q2", visibleIf: "!asyncFunc({q1})"
}
],
});
const q1 = survey.getQuestionByName("q1");
const q2 = survey.getQuestionByName("q2");
returnResult(true);
assert.equal(q2.isVisible, false, "visible #1");
q1.value = 1;
returnResult(false);
assert.equal(q2.isVisible, true, "visible #2");
FunctionFactory.Instance.unregister("asyncFunc");
}
);

QUnit.test(
"Focus errored question when checkErrorsMode: `onComplete` + onServerValidateQuestions, Bug#2466",
Expand Down