Single- and Multi-Select Questions with Custom Item Template
SurveyJS Form Library supports the usage of custom templates to change the appearance of choice options in Checkboxes, Radio Button Group, and other single- or multi-select question types. This demo shows how to customize choice options using a custom template component.
To create and apply a custom option template, follow the steps below:
Implement a component that renders option markup.
The component accepts the option configuration object as a prop. You can use itsvalue
andtext
properties to access the option's value to be saved in survey results and display text.Register the component so that it can be accessed by name.
In HTML/CSS/JavaScript projects, register the component inReactElementFactory
as shown in theindex.js
file.
In React, register the component inReactElementFactory
as shown in theSurveyComponent.jsx
file.
In Angular, register the component inAngularComponentFactory
as shown in thecustom-choice-item.component.ts
file.
In Vue 3 and Knockout, use techniques native to these libraries:Assign the component name to the question's
itemComponent
property in the survey JSON schema.