surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.21k stars 814 forks source link

Reevaluate expressions after a function is registered #7694

Closed SamMousa closed 10 months ago

SamMousa commented 10 months ago

Are you requesting a feature, reporting a bug or asking a question?

Question

What is the current behavior?

Say I have a function toUpper that changes a string to upper case. I create the survey model but only after it has been created the function toUpper is registered.

Can I tell the survey model to re-evaluate all calculations? Notes:

What is the expected behavior?

Ideally surveyJS should detect any function registration and update the relevant expressions automatically.

Alternatively there should be a clean way to notify SurveyJS that something has changed. For calculated values specifically I can work around it by doing this:

survey.calculatedValues[0].setOwner(survey.calculatedValues[0].data);

But this is not feasible for things like visibleIf, I'd have to iterate recursively over every element and check every expression again. Instead the proper solution is to add the function definition as a dependency and recalculate when the dependency is changed.

How would you reproduce the current behavior (if this is a bug)?

I don't think it's a bug but you can see demo sandbox below.

Provide the test code and the tested page URL (if applicable)

Tested page URL: https://codesandbox.io/p/sandbox/stupefied-cartwright-zdyrqt NOTE Due to the way knockout and the sandbox work, make sure you do an actual reload when testing changes. image

Specify your

SamMousa commented 10 months ago

Workaround for now: survey.setVariable('__someRandomName', 1) recalculates everything.

andrewtelnov commented 10 months ago

@SamMousa We have added survey.runExpressios() function that you can call.

Thank you, Andrew