Question T11640
Visible to All Users

Default localizable Text in custom questions

created 2 years ago

Hello everyone,
if i create a custom question like below. How can i add default text to the minimumLabel panel input.
Clipboard-File-1.png

Code
export class QuestionColorModel extends Question { constructor(name) { super(name); this.createLocalizableString("minimumLabel", this, true); this.createLocalizableString("maximumLabel", this, true); } getType() { return "color"; } get minimumLabel() { return this.getLocalizableStringText("minimumLabel"); } set minimumLabel(val) { this.setLocalizableStringText("minimumLabel", val); } get locMinimumLabel() { return this.getLocalizableString("minimumLabel"); } get maximumLabel() { return this.getLocalizableStringText("maximumLabel"); } set maximumLabel(val) { this.setLocalizableStringText("maximumLabel", val); } get locMaximumLabel() { return this.getLocalizableString("maximumLabel"); } }

and adding class info:

Code
Serializer.addClass("color",[ { name: "minimumLabel", displayName: "Mininimum Label", serializationProperty: "locMinimumLabel", category: "Label" }, { name: "maximumLabel", displayName: "Maximum Label", serializationProperty: "locMaximumLabel", category: "Label" }, } ], function () { return new QuestionColorModel(""); }, "question" );
Comments (1)

    Hello Cef,
    You can specify a default value for a custom property using the default property. You can find an example in our documentation: https://surveyjs.io/survey-creator/documentation/property-grid#default.

    Please let me know if it helps.

    Answers approved by surveyjs Support

    created 2 years ago

    Hello Cef,
    The localization strings get the default value from the translated strings. Here is the example of adding a new localizable string and it's default value for English locale:

    JavaScript
    Survey.Serializer.addProperty("question", {name:"buttonText"isLocalizabletrue }); const englishStrings = Survey.surveyLocalization.getLocaleStrings("en"); englishStrings["buttonText"] = "Default btn text";

    Here is the working example.

    Thank you,
    Andrew
    SurveyJS Team

      Show previous comments (3)

        I see, you have to say SurveyJS that you have the default value in the translation strings. It is the fourth parameter:

        JavaScript
        this.createLocalizableString('gdprAboutLabel', this, true, true); this.createLocalizableString('gdprLinkLabel', this, true, true);

        If you want to have a name in your localization strings different from your property name, then you can use the name as the forth parameter:

        JavaScript
        this.createLocalizableString('gdprAboutLabel', this, true, "aboutLabel"); this.createLocalizableString('gdprLinkLabel', this, true, "myLinkLabel");

        Thank you,
        Andrew
        SurveyJS Team

            Great!

            Andrew
            SurveyJS Team