Hi There,
I am writing to request support for the following requirements in creating a new custom question type:
- Issue with setting with custom properties: Currently facing challenges in setting values for custom properties.
- Display Name vs Back-end Type: I would like the custom question type to display as Counter Data in frontend, while in JSON Object the type should be counter-data.
- Custom Icon for new question type using SvgRegistry
Codeimport React from "react";
import { Question, Serializer, ElementFactory } from "survey-core";
import {
ReactQuestionFactory,
SurveyQuestionElementBase
} from "survey-react-ui";
const CUSTOM_QUESTION_TYPE = "counterdata";
export class CounterModel extends Question {
constructor(name) {
super(name);
this.dataType = "QueryString";
}
getType() {
return CUSTOM_QUESTION_TYPE;
}
}
class SurveyQuestionCounter extends SurveyQuestionElementBase {
get question() {
return this.questionBase;
}
renderElement() {
return <div>{this.question.value}</div>;
}
}
function registerCounterQuestion() {
ElementFactory.Instance.registerElement(CUSTOM_QUESTION_TYPE, (name) => {
return new CounterModel(name);
});
Serializer.addClass(
CUSTOM_QUESTION_TYPE,
[
{
name: "dataType",
category: "general",
visibleIndex: 2,
default: "Query String",
readOnly: true
},
{
title: "Query String",
name: "queryString",
category: "general",
visibleIndex: 3
}
],
function () {
return new CounterModel("");
},
"question"
);
ReactQuestionFactory.Instance.registerQuestion(
CUSTOM_QUESTION_TYPE,
(props) => {
return React.createElement(SurveyQuestionCounter, props);
}
);
}
export { registerCounterQuestion };
For you reference, I have attached a screen shot illustrating the desire behavior, and you can access demo link here