You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I am currently using surveyjs within a react app. I have a custom function that returns an uuid value and I invoke that function using an expression in the surveyjs JSON. Now, I have observed the following.
This uuid() has no parameter input, yet whenever I select any value from any other dropdown of any other field in the form that has no dependency with the uuid expression field, then also the uuid value of the expression gets updated - unnecessarily and this also causes a re-render.
If I have a function with a parameter input, this parameter input comes from a particular field of the survey. Now even if I alter another field that is not related to the parameter input of this expression custom function, then also expression gets re-evaluated, and the function is re-invoked. This also causes an unnecessary re-render.
Considering the obs#2, if I put the mentioned function with single param input within an iif() statement, such that the function should only be invoked if the condition is true, then also the expression containing the function gets evaluated even though the condition is false. This is preventing me from restricting a custom function call via iif statement.
Consider this example for understanding the scenario better.
Note: findServiceByModel() is already registered in a FunctionFactory instance and async in nature.
In this example
audit_id get re-evaluated each time I change audit_type dropdown value.
findServiceByModel() will get invoked even if I change audit_type which is completely independant.
findServiceByModel() will get invoked even if enable_model is set to false.
Ideally, expressions should only be re-evaluated if its dependent param changes else not.
Please let me know how the above concerns can be addressed in surveyjs.
@kalpadiptyaroy
There is an error in your expression, please correct it: iif({enable_model} == true, findServiceByModel({model})), 'null'
It should be: iif({enable_model} == true, findServiceByModel({model}), 'null')
We recalculate the expression whenever any value changes, which is currently by design. We perform checks for changing values in expressions related to triggers and question properties, such as defaultValueExpression or setValueExpression. It is important that we execute these expressions only when a particular question's values change.
However, if we encounter a function, we execute the expression anyway, as we cannot predict what might be contained within it. A developer might utilize any survey or question property inside a custom function.
Yes you are correct there is a typographical error in closing the parenthesis. My bad.
Keeping that aside.
I see you are executing the expression anyway if it is a bare expression - right? (not contained in a question prop or triggers).
So that means the behavior I want can be achieved by utilizing the expressions in the questions props or triggers - Fine.
May I request a small example in Plunker that demonstrates both the scenarios (meaning bare expression and another as a part of a trigger and a question prop). That will be helpful reference for me at this stage in my use case.
Describe the bug
I am currently using surveyjs within a react app. I have a custom function that returns an uuid value and I invoke that function using an expression in the surveyjs JSON. Now, I have observed the following.
This uuid() has no parameter input, yet whenever I select any value from any other dropdown of any other field in the form that has no dependency with the uuid expression field, then also the uuid value of the expression gets updated - unnecessarily and this also causes a re-render.
If I have a function with a parameter input, this parameter input comes from a particular field of the survey. Now even if I alter another field that is not related to the parameter input of this expression custom function, then also expression gets re-evaluated, and the function is re-invoked. This also causes an unnecessary re-render.
Considering the obs#2, if I put the mentioned function with single param input within an iif() statement, such that the function should only be invoked if the condition is true, then also the expression containing the function gets evaluated even though the condition is false. This is preventing me from restricting a custom function call via iif statement.
Consider this example for understanding the scenario better.
Steps to reproduce
Expected behavior
Note: findServiceByModel() is already registered in a FunctionFactory instance and async in nature.
In this example
audit_id get re-evaluated each time I change audit_type dropdown value.
findServiceByModel() will get invoked even if I change audit_type which is completely independant.
findServiceByModel() will get invoked even if enable_model is set to false.
Ideally, expressions should only be re-evaluated if its dependent param changes else not.
Please let me know how the above concerns can be addressed in surveyjs.
Evidence
Stacktrace evidence:
Please complete the following information:
Additional context
https://stackoverflow.com/questions/79299024/how-to-restrict-re-evaluation-of-expressions-for-only-those-change-in-values-on
The text was updated successfully, but these errors were encountered: