Question T7119
Visible to All Users

Programmatically add title and description

created 4 years ago

If survey title and description are already set (in Translation Tab), I can access their values and add new languages like this:

JavaScript
this.surveyCreator.JSON.description.en = "My title; this.surveyCreator.JSON.description.lv = "Nosaukums;

However, if they are not set in UI, I cannot set them in code. The following sample does not work as I would expect.

JavaScript
this.surveyCreator.JSON.description = { en: "My title", default: "My title" }; console.log(this.surveyCreator.JSON.description); // this appears to be undefined this.surveyCreator.JSON.description.lv = "Desc LV"; // this throws "TypeError: Cannot set property 'lv' of undefined"

How can I set title and description programmatically?

Answers approved by surveyjs Support

created 4 years ago

Hello,
If you want to do it using survey model please use the following code:
survey.locTitle.setLocaleText("lv", "Your text"); and to get locale valuesurvey.locTitle.getLocaleText("lv");
every localizable string has "locPropertyName" property, so for description it will be "locDescription".
You can use the same approach in creator as: creator.survey.locTitle.setLocaleText("lv", "Your text");

Thank you,
Andrew
SurveyJS Team