Question T2383
Visible to All Users

Removing properties for questions created by custom toolbox item

created 6 years ago (modified 6 years ago)

Hi,

I'm looking for a way to remove properties for questions created by a custom toolbox item. For example, to remove the visible property from a custom placeholders toolbox item, I'd do:

JavaScript
creator.toolbox.addItem({ name: "placeholders", iconName: "icon-default", title: "Placeholders", json: { type: "multipletext", optionsCaption: "Placeholders", items: [] } }); SurveyKo.Serializer.removeProperty("placeholders", "visible");

Unfortunately, "placeholders" isn't a class name recognized by the serializer, so the last statement is a noop.

Is there an alternative way to achieve it?

Answers approved by surveyjs Support

created 6 years ago

Hello,
You can't remove visible property, since it is defined in base question class.
You may make it invisible for "multipletext", this is the class you use here. "placeholders" is just a name for toolbox item.
You may override the visible property using the following code:

JavaScript
SurveyKo.Serializer.addProperty("multipletext", {name: "visible", visible: false});

You may add your 'placehoders" class dynamically, and use it in your JSON. You will have to understand that it is the custom class and you will have to run this code on all pages where you use this JSON.

JavaScript
SurveyKo.Serializer.addClass( "placeholders", [ {name: "visible", visible: false}], null, "multipletext");

Thank you,
Andrew
SurveyJS Team

    Other Answers

    created 6 years ago (modified 6 years ago)

    Thanks, this works for hiding properties visible in the parent classes. However the same technique doesn't seem to work for showing properties explicitly not visible in the parent classes.

    JavaScript
    SurveyKo.Serializer.findProperty("question", "defaultValue").visible = false SurveyKo.Serializer.addClass( "placeholders", [{ name: "defaultValue", visible: true }], null, "multipletext" ); // ... creator.toolbox.addItem({ name: "placeholders", iconName: "icon-default", title: "Placeholders", json: { type: "placeholders", optionsCaption: "Placeholders", items: [] } });

    Is this something that can be worked around?

      Show previous comments (12)

        Thanks!

          Hi,

          I want to hide 'readOnly' property to my custom Item.

          My toolbox item:

          JavaScript
          creator.toolbox.addItem({ name: "clientinfofield", isCopied: true, iconName: "icon-default", title: "Información del Cliente", json: { 'type': "text", 'customType': 'clientinfofield', optionsCaption: "Select a country...", readOnly: true, showReadOnly: false, choices: [ { value: "clientRef", text: "Client REF" } ] } });

          I'm trying with these options, but don't work:
          1.Survey.Serializer.addProperty("clientinfofield", {name: "readOnly", visible: false});
          2.If you see, I added a custom property in json object 'customType', to try get it here and hide the property:

          JavaScript
          formCreator .onShowingProperty .add(function (sender, options) { if (options.obj.customType == "clientinfofield" && options.property.name == "readOnly") { options.canShow = false; } });

          any idea?, or can I not allow to user change that property for my custom toolbox item?.

            Hello,

            I've created a separate ticket on your behalf (T3890: Hide 'readOnly' property for my custom class). It has been placed in our processing queue and will be answered shortly.