-
Notifications
You must be signed in to change notification settings - Fork 80
/
MyQuestion.js
54 lines (46 loc) · 1.17 KB
/
MyQuestion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Question, Serializer, ElementFactory } from "survey-core";
import { SurveyElementBase, ReactQuestionFactory } from "survey-react-ui";
const QUESTION_TYPE = "myquestion";
export function registerMyQuestion() {
ElementFactory.Instance.registerElement(QUESTION_TYPE, (name) => {
return new MyQuestionModel(name);
});
}
export class MyQuestionModel extends Question {
getType() {
return QUESTION_TYPE;
}
get text() {
return this.getPropertyValue("text", "");
}
set text(newValue) {
this.setPropertyValue("text", newValue);
}
}
export class MyQuestion extends SurveyElementBase {
get question() {
return this.props.question;
}
render() {
if (!this.question) return null;
const cssClasses = this.question.cssClasses;
return (
<div className={cssClasses.root}>
<span>My Text Value: </span><span><b>{this.question.text}</b></span>
</div>
);
}
}
Serializer.addClass(
QUESTION_TYPE,
[
{ name: "text" }
],
function () {
return new MyQuestionModel("");
},
"question"
);
ReactQuestionFactory.Instance.registerQuestion(QUESTION_TYPE, props => {
return React.createElement(MyQuestion, props);
});