|
1 |
| -# React quickstart boilerplate for SurveyJS: Survey Library and Survey Creator |
| 1 | +# SurveyJS + React Quickstart Template |
2 | 2 |
|
3 |
| -This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). |
| 3 | +SurveyJS is a set of JavaScript components that allow you and your users to build surveys / forms, store them in your database, and visualize survey results for data analysis. This quick start template is bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app) and uses the following SurveyJS components: |
4 | 4 |
|
5 |
| -## How to run this sample application |
6 |
| - - git clone https://github.com/surveyjs/surveyjs_react_quickstart.git |
7 |
| - - cd surveyjs_react_quickstart |
8 |
| - - npm i |
9 |
| - - npm start |
10 |
| - - open http://localhost:3000/ in your web browser |
| 5 | +- [SurveyJS Library / Runner](https://surveyjs.io/Documentation/Library?id=LibraryOverview) |
| 6 | +- [Survey Creator / Form Builder](https://surveyjs.io/Documentation/Survey-Creator?id=Survey-Creator-Overview) |
| 7 | +- [PDF Export](https://surveyjs.io/Documentation/Pdf-Export?id=PdfExportOverview) |
| 8 | +- [Survey Analytics](https://surveyjs.io/Documentation/Analytics?id=AnalyticsOverview) |
11 | 9 |
|
| 10 | +## Run the application |
12 | 11 |
|
13 |
| - |
14 |
| -You can find the detailed information on how to perform common tasks in [this guide](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md). |
15 |
| - |
16 |
| -## Add survey component on your page |
17 |
| -```JavaScript |
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 |
| - } |
45 |
| -} |
| 12 | +```bash |
| 13 | +git clone https://github.com/surveyjs/surveyjs_react_quickstart.git |
| 14 | +cd surveyjs_react_quickstart |
| 15 | +npm i |
| 16 | +npm run start |
46 | 17 | ```
|
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 | 18 |
|
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 |
| -``` |
| 19 | +Open http://localhost:3000/ in your web browser. |
| 20 | + |
| 21 | +## Template structure |
| 22 | + |
| 23 | +This template covers most basic use cases. You can find code examples for them in the following files: |
| 24 | + |
| 25 | +- Create a standalone survey |
| 26 | + - [src/data/survey_json.js](src/data/survey_json.js) |
| 27 | + - [src/pages/Survey.js](src/pages/Survey.js) |
| 28 | +- Add Survey Creator to a page |
| 29 | + - [src/components/SurveyCreator.js](src/components/SurveyCreator.js) |
| 30 | + - [src/pages/Creator.js](src/pages/Creator.js) |
| 31 | +- Export a survey to a PDF document |
| 32 | + - [src/pages/Export.js](src/pages/Export.js) |
| 33 | +- Visualize survey results |
| 34 | + - As charts |
| 35 | + - [src/data/analytics_data.js](src/data/analytics_data.js) |
| 36 | + - [src/components/SurveyAnalytics.js](src/components/SurveyAnalytics.js) |
| 37 | + - [src/pages/Analytics.js](src/pages/Analytics.js) |
| 38 | + - As a table (modern browsers) |
| 39 | + - [src/data/analytics_data.js](src/data/analytics_data.js) |
| 40 | + - [src/components/SurveyAnalyticsTabulator.js](src/components/SurveyAnalyticsTabulator.js) |
| 41 | + - [src/pages/AnalyticsTabulator.js](src/pages/AnalyticsTabulator.js) |
| 42 | + - As a table (old browsers) |
| 43 | + - [src/data/analytics_data.js](src/data/analytics_data.js) |
| 44 | + - [src/components/SurveyAnalyticsDatatables.js](src/components/SurveyAnalyticsDatatables.js) |
| 45 | + - [src/pages/AnalyticsDatatables.js](src/pages/AnalyticsDatatables.js) |
| 46 | +- Create a custom question type |
| 47 | + - [src/components/MyQuestion.js](src/components/MyQuestion.js) |
| 48 | +- Register third-party components |
| 49 | + - [src/App.js](src/App.js#L37) |
0 commit comments