Question T14430
Visible to All Users

Need to access the question type while adding a custom property

created a year ago

Hi,

I am trying to add new property for Options Items which should be enable only for Checkbox & Radio type of questions. I tried to add property in below way but the parameter of visibleIf gives data of Item Value not the actual question. How can I access the data of question to set the visibility?

Code
Serializer.addProperty('itemvalue', {     name: 'o_comment',     type: 'boolean',     default: false,     visibleIf: (obj) => {       debugger;     }   })

Thanks,
Santosh

Answers approved by surveyjs Support

created a year ago

Hello Santosh,
If you wish to display a custom itemvalue property for Checkbox and Radiogroup question types only, instead of the visibleIf expression, manage the custom setting visibility using the creator.onShowingProperty event.

Please consider this example: View Demo.

JavaScript
import { Serializer } from "survey-core"; Serializer.addProperty("itemvalue", { name: "o_comment", type: "boolean", default: false }); creator.onShowingProperty.add(function (sender, options) { if (options.property.name === "o_comment") { if (!!options.parentObj) { const surveyElementType = options.parentObj.getType(); options.canShow = surveyElementType === "radiogroup" || surveyElementType === "checkbox"; } } });

For more information, refer to the following demo: Hide a Category from the Property Grid.

Drop me a line if you have any further questions.

    Comments (2)

      Hi Jane,

      Thank you so much for the response. This is working for me now.

      I am facing one more issue. The custom property i have added for item value is type of checkbox which is showing label. Is it possible to hide the label here?

      Clipboard-File-1.png

      Thanks,
      Santosh

        Hi Santosh,
        You're always welcome.

        To process your recent inquiry in the most efficient manner, I created a separate ticket on your behalf: T14435: Hide a label for a custom Boolean property. We placed it in our processing queue and will process it shortly.