Question T14359
Visible to All Users

How to set a default value to a property in a custom widget

created a year ago

I have a custom widget which I want to set the titleLocation to hidden and the hideNumber to true by default - but still be able to edit it if I want to in the creator. How do I accomplish this?

Answers approved by surveyjs Support

created a year ago

Hi Brian,
You can use the Serializer.getProperty('questionType', 'propertyName') function to obtain target settings of your custom widget and set the defaultValue attribute:

JavaScript
Survey.Serializer.getProperty('customWidgetType', 'titleLocation').defaultValue = 'hidden'; Survey.Serializer.getProperty('customWidgetType', 'hideNumber ').defaultValue = true;

Please let me know if this code works for you.

    Comments (2)
    A A
    Ahmad Al-waili a year ago

      Hi,

      The following code:

      Code
      SurveyLib.Serializer.getProperty(   'datasheet',   'showCommentArea' ).defaultValue = true;

      This is meant to show the comment area by default, and check the box by default.

      However, this is not the case. Am i doing something wrong?
      Clipboard-File-1.png

        Hello Ahmad,

        I created a separate ticket on your behalf: T15355: A comment section does not appear by default. We placed it in our processing queue and will process it shortly.