Custom Question Renderer
Each SurveyJS question type comes with a predefined renderer—a component that specifies the question's markup. If you want to customize a question's appearance, you can implement a custom renderer and use it instead of the predefined renderer, as shown in this demo for Radio Button Group questions.
Follow the instructions below to implement a custom renderer in your survey:
Create a component that renders your custom markup.
If the component reuses a predefined renderer, its class should extend one of the predefined classes. For example, in this demo, a custom component adds an image to a predefined Radio Button Group question. The component's class extends Radio Button Group's class (see theRadiogroupWithImageQuestionclass).Register your component under a custom name in the component collection.
In HTML/CSS/JavaScript projects, register the component inReactElementFactoryas shown in theindex.jsfile.
In React, register the component inReactElementFactoryas shown in theSurveyComponent.jsxfile.
In Angular, register the component inAngularComponentFactoryas shown in thecustom-radiogroup.component.tsfile.
In Vue.js, use techniques native to this framework.Register your component as a renderer for a selected question type.
Use theRendererFactory.Instance.registerRenderer(questionType, renderAs, rendererName, useAsDefault)method that accepts the following parameters:questionType:string- A question type for which this renderer can be used.renderAs:string- A name that activates this renderer. This name should be assigned to therenderAsproperty in JSON.rendererName:string- The custom renderer's name under which you registered it in step 2.useAsDefault:boolean- A flag that defines whether to use the custom component as a default renderer for all questions of the specifiedquestionType. Default value:false.
Specify the
renderAsproperty in the survey JSON schema.
Set this property to therenderAsname under which you register the custom renderer in step 3. Specify therenderAsproperty only for those questions that should use the custom renderer. You can skip this step if you passtrueas theuseAsDefaultparameter in the previous step.