Question T12071
Visible to All Users

Disable Name field in a question

created 2 years ago

Hi Team,

Can I know how to disable a Name field of a question?

Thanks and Regards,
Santosh

Answers approved by surveyjs Support

created 2 years ago (modified 2 years ago)

[Updated]

You can run the following code to set a name property read-only:

JavaScript
import { Serializer } from "survey-core"; Serializer.findProperty("question", "name").readOnly = true;

Please refer to the following example on our website: Modify New Question.

To set a property read-only for specific questions, handle the creator.onGetPropertyReadOnly function. The following code disables the name property for all Radiogroup questions:

Code
JavaScriptcreator.onGetPropertyReadOnly.add(function(sender, options){ options.readOnly = options.obj.getType() === 'radiogroup' && options.propertyName === 'name'; });
    Show previous comments (3)

      Hi Santosh,
      With the creator.onGetPropertyReadOnly function, you can disable any property as per your needs dictate.

      Consider the following code. It disables the name property for all Radiogroup questions:

      JavaScript
      creator.onGetPropertyReadOnly.add(function(sender, options){ options.readOnly = options.obj.getType() === 'radiogroup' && options.propertyName === 'name'; });

      Please let me know if this code can help you.

        Hi Jane,

        Working as expected. Thank you for the quick response.

        Thanks and Regards,
        Santosh

          You're always welcome, Santosh.

          Please feel free to contact us if you have any questions or require further assistance.