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

Expression results are stringified #7050

Closed
FHourmy opened this issue Sep 29, 2023 · 3 comments
Closed

Expression results are stringified #7050

FHourmy opened this issue Sep 29, 2023 · 3 comments
Assignees
Labels
bug user issue An issue or bug reported by users
Milestone

Comments

@FHourmy
Copy link

FHourmy commented Sep 29, 2023

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

Bug
This behavior is introduced by the version 1.9.108

What is the current behavior?

the result of an expression which is a complex type is stringified.

What is the expected behavior?

the result of an expression if it is a complex type should not be stringified

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

sandbox : https://codesandbox.io/s/fervent-feynman-syklql
you can see in the log data when you change the text question value that the value of the question testExpression is a stringified array instead of

Specify your

  • browser: chrome
  • surveyjs platform (angular or react or jquery or knockout or vue): jquery
  • surveyjs version: 1.9.108
@JaneSjs JaneSjs self-assigned this Oct 2, 2023
@JaneSjs JaneSjs added user issue An issue or bug reported by users bug and removed bug labels Oct 5, 2023
@JaneSjs
Copy link
Contributor

JaneSjs commented Oct 5, 2023

Hello @FHourmy,
Thank you for sharing a demo. I tested your sample and confirmed that this behavior exists in an older version of a SurveyJS Form Library (for instance, 1.9.90). Would you please elaborate on the expected behavior?
For now, you can programmatically convert an array of values into a required representation.

Consider the updated demo: https://codesandbox.io/s/focused-poincare-w6p6zt?file=/index.js:43-218.

Survey.FunctionFactory.Instance.register("testExpression", () => {
  const values = [{ value: "t1" }, { value: "t2" }];
  const res = JSON.stringify(values);
  return res;
});

Thanks

@FHourmy
Copy link
Author

FHourmy commented Oct 6, 2023

Hello @JaneSjs
The problem is the type of stored value. you can see it in the console

in version 1.9.108 the current behavior

The returned value is stored as a string [object,object
image
repro on https://codesandbox.io/s/fervent-feynman-syklql?file=/index.js

in older version the expected behavior (for instance 1.9.90)

The returned value is stored in the same way it is returned, conserving its type
image
repro on https://codesandbox.io/s/festive-lewin-kv82v3?file=/index.html

In your edit

You stringify the array to store it, losing its type and potential complex properties (can't store functions this way for exemple)
image
repro on https://codesandbox.io/s/focused-poincare-w6p6zt?file=/index.js

Thank you for your time :)

@andrewtelnov
Copy link
Member

@FHourmy The issue was introduced by fixing this issue.
I have changed the fix. In fact, it was fixed incorrectly. I should not change the expression question model code.
I wrote the correct unit tests for that fix and added unit test for your case in the PR above.

Thank you,
Andrew

@tsv2013 tsv2013 closed this as completed in 6cfbbd1 Oct 6, 2023
@RomanTsukanov RomanTsukanov changed the title Result of expression question is stringified Expression results are stringified Oct 10, 2023
@OlgaLarina OlgaLarina added this to the v1.9.112 milestone Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug user issue An issue or bug reported by users
Projects
None yet
Development

No branches or pull requests

4 participants