Question T11121
Visible to All Users

Adding a React component to a Custom Component's Property Grid

created 2 years ago

Hello.

I can see from Override the Property Grid's component, Survey Creator Example (surveyjs.io) that it's possible to register a React component in the property grid with

JavaScript
SurveyReact .ReactElementFactory .Instance .registerElement("svc-property-grid", (props) => { return React.createElement(CustomPropertyGridWrapper, props); });

Now, I want to create a CustomPropertyGridWrapper but display it only when my custom component is active. I have added my custom component using this as a template surveyjs_react_quickstart/MyQuestion.js at master · surveyjs/surveyjs_react_quickstart · GitHub

Answers approved by surveyjs Support

created 2 years ago (modified 2 years ago)

Hello Michal,
I recalled this usage scenario and updated the code shared initially to demonstrate how to use a custom Test React component as a property editor. The idea is to override a default renderer for a standard question type (the dropdown in our case):

JavaScript
ReactQuestionFactory.Instance.registerQuestion( "sv-fileupload-react", (props) => { return React.createElement(Test, props); } ); RendererFactory.Instance.registerRenderer( "dropdown", "my-custom-component", "sv-fileupload-react" );

Now, you can declare a property of a custom file-upload type:

JavaScript
Survey.Serializer.addProperty("question", { name: "Test", type: "fileupload", isRequired: false, category: "general", visibleIndex: 1 });

And register a custom property grid editor for this custom property. In the getJson function, return a dropdown question type and specify a custom renderer:

JavaScript
PropertyGridEditorCollection.register({ fit: function (prop) { return prop.type === "fileupload"; }, getJSON: function (obj, prop, options) { return { type: "dropdown", renderAs: "my-custom-component" }; } });

Example.
Clipboard-File-1.png
I hope this example will be of help. Should you have any questions or require further assistance, drop us a line.

Thanks

    created 2 years ago

    Hello,

    You can register an alternative renderer as shown in this live example on our site - https://surveyjs.io/form-library/examples/custom-widget-react-select/reactjs#content-js
    and set it for your custom editor:

    JavaScript
    SurveyCreator.PropertyGridEditorCollection.register({ fit: function (prop) { return prop.type === "fileupload"; }, getJSON: function (obj, prop, options) { return { type: "text", renderAs: "my-custom-file" } } });

    Thanks, Serge
    SurveyJS Team

      Show previous comments (5)

        Hello Michal,
        I've updated your example and registered a custom fileupload class. Please check the sample: https://codesandbox.io/s/distracted-microservice-t1vs2r?file=/src/SurveyCreator.jsx.

        Let me know if it works for you.

          Thanks Jane. That's exactly what I needed! Cheers

            You're very welcome!
            Please feel free to contact us if you have any questions or require further assistance.

            If you have free time, we would love if you could leave your feedback on SurveyJS page at g2.com. As we’re building our business, every review helps build credibility for future customers and your feedback would be greatly appreciated.

            Thank you