Skip to content

Commit c3a3930

Browse files
author
T_S_V
committed
# Conflicts: # package.json # src/Creator.js # src/Export.js # src/Survey.js # src/SurveyCreator.js
2 parents def42f7 + a494af6 commit c3a3930

File tree

2 files changed

+135
-297
lines changed

2 files changed

+135
-297
lines changed

README.md

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,71 @@ You can find the detailed information on how to perform common tasks in [this gu
1515

1616
## Add survey component on your page
1717
```JavaScript
18-
//In your react App.js or yourComponent.js file add these lines to import
19-
import * as Survey from "survey-react";
20-
import "survey-react/survey.css";
21-
22-
class App extends Component {
23-
//Define Survey JSON
24-
//Here is the simplest Survey with one text question
25-
json = {
26-
elements: [
27-
{ type: "text", name: "customerName", title: "What is your name?", isRequired: true}
28-
]
29-
};
30-
31-
//Define a callback methods on survey complete
32-
onComplete(survey, options) {
33-
//Write survey results into database
34-
console.log("Survey results: " + JSON.stringify(survey.data));
35-
}
36-
render() {
37-
//Create the model and pass it into react Survey component
38-
//You may create survey model outside the render function and use it in your App or component
39-
//The most model properties are reactive, on their change the component will change UI when needed.
40-
var model = new Survey.Model(this.json);
41-
return (<Survey.Survey model={model} onComplete={this.onComplete}/>);
42-
/*
43-
//The alternative way. react Survey component will create survey model internally
44-
return (<Survey.Survey json={this.json} onComplete={this.onComplete}/>);
45-
*/
46-
//You may pass model properties directly into component or set it into model
47-
// <Survey.Survey model={model} mode="display"/>
48-
//or
49-
// model.mode="display"
50-
// <Survey.Survey model={model}/>
51-
// You may change model properties outside render function.
52-
//If needed react Survey Component will change its behavior and change UI.
53-
}
18+
import React, { Component } from "react";
19+
import * as Survey from "survey-core";
20+
import * as SurveyReact from "survey-react-ui";
21+
//Import localization
22+
import "survey-core/survey.i18n.js";
23+
//Import Survey styles
24+
import "survey-core/defaultV2.css";
25+
26+
class SurveyComponent extends Component {
27+
constructor() {
28+
super();
29+
const json = {
30+
elements: [
31+
{ type: "text", name: "customerName", title: "What is your name?", isRequired: true }
32+
]
33+
};
34+
this.survey = new Survey.Model(json);
35+
this.survey.onValueChanged.add((sender, options) => {
36+
console.log("value changed!");
37+
});
38+
this.survey.onComplete.add((sender, options) => {
39+
console.log("Complete! Response:" + JSON.stringify(sender.data));
40+
});
41+
}
42+
render() {
43+
return <SurveyReact.Survey model={this.survey} />;
44+
}
5445
}
5546
```
47+
## Add creator component on your page
48+
```JavaScript
49+
import React, { Component } from "react";
50+
import * as Survey from "survey-core";
51+
import * as SurveyReact from "survey-react-ui";
52+
import * as SurveyCreatorCore from "survey-creator-core";
53+
import * as SurveyCreator from "survey-creator-react";
54+
//Import Survey localization
55+
import "survey-core/survey.i18n.js";
56+
//Import Survey Creator localization
57+
import "survey-creator-core/survey-creator-core.i18n.js";
58+
59+
//Import Survey and Creator styles
60+
import "survey-core/defaultV2.css";
61+
import "survey-creator-core/survey-creator-core.css";
62+
63+
class CreatorComponent extends Component {
64+
constructor() {
65+
super();
66+
const json = {
67+
elements: [
68+
{ type: "text", name: "customerName", title: "What is your name?", isRequired: true }
69+
]
70+
};
71+
const options = { showLogicTab: true };
72+
this.creator = new SurveyCreator.SurveyCreator(options);
73+
this.creator.saveSurveyFunc = this.saveMySurvey;
74+
this.creator.JSON = json;
75+
}
76+
render() {
77+
return (<div>
78+
<SurveyCreator.SurveyCreatorComponent creator={this.creator} />
79+
</div>);
80+
}
81+
saveMySurvey = () => {
82+
console.log(JSON.stringify(this.creator.text));
83+
};
84+
}
85+
```

0 commit comments

Comments
 (0)