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

Cannot set default for completedHtml and similar properties #5405

Open
SamMousa opened this issue Apr 11, 2024 · 4 comments
Open

Cannot set default for completedHtml and similar properties #5405

SamMousa opened this issue Apr 11, 2024 · 4 comments
Labels

Comments

@SamMousa
Copy link
Contributor

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

Bug

What is the current behavior?

Changing the default value for completedHtml does not work.

What is the expected behavior?

Changing the default value should work.

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

Complete the survey in the preview tab in the link below.

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

Tested page URL: https://codesandbox.io/p/sandbox/priceless-germain-g3fcht

Test code

const completedHtml = Serializer.findProperty("survey", "completedHtml");
completedHtml.default = "test";

@andrewtelnov
Copy link
Member

@SamMousa It is a localizable property with predefine translation for all locales.
You need to modify it as the following.

const enTranslations = Survey.surveyLocalization.getLocaleStrings("en")
const frTranslations = Survey.surveyLocalization.getLocaleStrings("fr")
enTranslations.completingSurvey = "test-en";
frTranslations.completingSurvey = "test-fr";

Thank you,
Andrew

@SamMousa
Copy link
Contributor Author

Should we not unify this from the perspective of a developer? Essentially what you're saying is that for each property I need to change defaults in different ways.

If I add a new property that is localizable I can set the default in the property definition, which makes it inconsistent.
Furthermore due to the way this is currently implemented it means that sometimes we actually save the default value in the survey JSON for no reason:

  1. Go to https://surveyjs.io/create-free-survey
  2. Change the thank you URL to anything
  3. Change it back to <h3>Thank you for completing the survey</h3>

Now the survey JSON contains this value. To make matters worse, now running the survey in a different language will not use the built in translations because it is seen as a user value (and the user value does not contain translations in this example).

In conclusion: this is bad for both DX and UX. I'm not sure how we could improve this to simplify the code while at the same time improving DX and UX.

@andrewtelnov
Copy link
Member

@SamMousa It is not understadable when to use the default value. Should we use it for "en" locale only or for all locales?
You can define the default value for a string, but not for a localizable string.

Thank you,
Andrew

@SamMousa
Copy link
Contributor Author

I agree with your points, so let's implement this in the DX!

> const completedHtml = Serializer.findProperty("survey", "completedHtml");
> completedHtml.default = "test";
< throw "Serialized localizable properties do not support changing their defaults, change the translations instead

The idea is that we need to rely less on people "knowing" stuff, or worse, asking every time, but more on implementing this properly in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants