Skip to content

Commit

Permalink
! operator with async expressions causes error fix #7268 (#7272)
Browse files Browse the repository at this point in the history
* ! operator with async expressions causes error fix #7268

* Typo in unit test #7268
  • Loading branch information
andrewtelnov committed Nov 1, 2023
1 parent 4c97513 commit f384178
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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

0 comments on commit f384178

Please sign in to comment.