-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget-started.html
More file actions
executable file
·391 lines (369 loc) · 20.4 KB
/
get-started.html
File metadata and controls
executable file
·391 lines (369 loc) · 20.4 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Get Started | surveyJS - JavaScript Survey Creation & Management. Made Easy</title>
<meta name="description" content="JavaScript Survey Creation & Management. Made Easy">
<meta name="keywords" content="survey, question, answer, javascript, plugin, ajax, json">
<meta name="author" content="Valerio Di Punzio">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://fonts.googleapis.com/css?family=Expletus+Sans:500|Raleway:200&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/font-awesome.css">
<link rel="stylesheet" href="css/doc.css">
<link rel="stylesheet" href="css/prism.css">
<script defer src="js/prism.js"></script>
<script defer src="js/vendors/jquery-1.12.4.min.js"></script>
<script defer src="js/vendors/bootstrap.bundle.min.js"></script>
<script defer src="js/include.js"></script>
</head>
<body>
<div id="top" class="container-fluid d-flex flex-column">
<div id="menu" class="position-sticky text-right d-flex">
<div class="position-raltive w-100">
<a href="index.html" class="logo">S</a>
<nav class="position-absolute nav-desktop d-none d-md-flex align-items-center">
<a href="index.html" class="p-2 m-2">Home</a>
<a href="get-started.html" class="p-2 m-2">Get Started</a>
<a href="api.html" class="p-2 m-2">API</a>
<a href="demos.html" class="p-2 m-2">Demos</a>
<a href="https://github.com/SimplySayHi/surveyJS" target="_blank" class="github-logo ml-2">
<svg version="1.1" id="Livello_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="28px" height="28px" viewBox="0 0 32 32" enable-background="new 0 0 32 32" xml:space="preserve">
<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M16,0.112c-8.836,0-16,7.294-16,16.291 C0,23.6,4.584,29.706,10.942,31.86c0.801,0.148 1.093-0.354,1.093-0.785c0-0.387-0.015-1.412-0.021-2.771 c-4.451,0.984-5.39-2.184-5.39-2.184c-0.729-1.881-1.777-2.383-1.777-2.383c-1.452-1.01,0.11-0.99,0.11-0.99 .605,0.115,2.45,1.68,2.45,1.68c1.428,2.488,3.745,1.77,4.657,1.354c0.145-1.053,0.559-1.771,1.016-2.178 c-3.553-0.412-7.288-1.809-7.288-8.051c0-1.778,0.623-3.232,1.646-4.371c-0.164-0.412-0.713-2.068,0.157-4.311 c0,0,1.344-0.438,4.399,1.67c1.276-0.361,2.646-0.543,4.006-0.549c1.359,0.006,2.728,0.188,4.006,0.549 c3.056-2.108,4.396-1.67,4.396-1.67c0.873,2.242,0.323,3.898,0.159,4.311c1.024,1.139,1.644,2.593,1.644,4.371 c0,6.258-3.74,7.635-7.305,8.038c0.574,0.504,1.086,1.498,1.086,3.018c0,2.178-0.02,3.934-0.02,4.469 c0,0.436,0.288,0.941,1.101,0.783C27.421,29.7,32,23.598,32,16.403C32,7.406,24.837,0.112,16,0.112z" />
</svg>
</a>
</nav>
<div class="position-absolute dropdown d-inline-block d-md-none">
<button class="btn dropdown-toggle dropdown-red-outline py-0 px-2" data-toggle="dropdown" type="button">
menu
</button>
<span class="dropdown-menu">
<a class="dropdown-item" href="index.html">Home</a>
<a class="dropdown-item" href="get-started.html">Get Started</a>
<a class="dropdown-item" href="api.html">API</a>
<a class="dropdown-item" href="demos.html">Demos</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="https://github.com/SimplySayHi/surveyJS" target="_blank">View on Github</a>
<a class="dropdown-item" href="https://github.com/SimplySayHi/surveyJS/issues" target="_blank">Report a Bug</a>
</span>
</div>
</div>
</div>
<div class="page-content mt-5 pt-5">
<h4 class="m-0 px-2">surveyJS</h4>
<h1 class="border-0 m-0">Get Started</h1>
<!-- Install -->
<div id="dependencies">
<h3 class="sticky-title">Dependencies</h3>
<p>
surveyJS is developed with these dependencies:
</p>
<ul>
<li>
<a href="https://github.com/SimplySayHi/formJS" target="_blank">formJS</a> ( version 5.2.0 or higher - for survey form validation and submit - NOT for <span class="badge badge-pill badge-yellow">Lite</span> version )
</li>
<li>
Bootstrap 4 CSS ( Optional - only form CSS ) but you can write the CSS by yourself ;)
</li>
</ul>
</div>
<!-- Install -->
<div id="install">
<h3 class="sticky-title">Install</h3>
<div class="row justify-content-between">
<div class="col-lg-5">
<p>
Include these scripts in your page:
</p>
<pre>
<code class="language-html"><script src="https://unpkg.com/formjs-plugin@5"></script>
<script src="https://unpkg.com/surveyjs@4"></script>
</code></pre>
<pre>
<code class="language-html"><script src="https://cdn.jsdelivr.net/gh/simplysayhi/formJS@5/dist/formjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/simplysayhi/surveyJS@4/dist/surveyjs.min.js"></script>
</code></pre>
</div>
<div class="col-lg-auto align-self-center d-none d-lg-block mt-3 pt-3">
OR
</div>
<div class="col-lg-5">
<p>
<span class="d-inline d-lg-none">or</span> Install via NPM and import as ES Module:
</p>
<pre>
<code class="language-markup">npm install formjs-plugin@5 surveyjs
</code></pre>
<pre>
<code class="language-js">import Survey from 'surveyjs';
</code></pre>
</div>
</div>
<hr />
<p>
In folder <code>dist</code> ( and via CDNs ) are also available these versions:
</p>
<ul>
<li>
ES Module
</li>
<li>
SystemJS
</li>
<li>
<span class="badge badge-pill badge-yellow">Lite</span> - in folder <code>dist/lite</code>
</li>
</ul>
</div>
<!-- HTML -->
<div id="html">
<h3 class="sticky-title">HTML</h3>
<div class="row">
<div class="col-lg-6">
<p>
Basic HTML structure to initialize the survey.<br />
Questions & answers will be put inside element with attribute <code>data-surveyjs-body</code>.
</p>
<pre>
<code class="language-html"><div class="surveyjs-wrapper" data-surveyjs-wrapper>
<form action="page.jsp" name="surveyjs-form" class="surveyjs-form" data-surveyjs-form novalidate>
<div class="surveyjs-body" data-surveyjs-body></div>
<div class="surveyjs-footer">
<button type="submit">SEND</button>
</div>
</form>
</div>
</code></pre>
<p>
Mandatory attributes:
</p>
<ul>
<li class="my-2">
<code>data-surveyjs-*</code> attributes
</li>
<li class="my-2">
<code>action</code> the page where to send the users answers ( with the AJAX call ) - NOT for <span class="badge badge-pill badge-yellow">Lite</span> version
</li>
</ul>
<p>
CSS classes ( like <code>.surveyjs-*</code> ) are optional but used to give styles to the demos.
</p>
</div>
<div class="col-lg-6">
<p>
To add one ( or more ) <b>external questions</b> ( for example privacy acceptance ) you can set a question object as shown in the JSON ( see question with <code>external: true</code> ):
</p>
<pre>
<code class="language-html"><div class="surveyjs-question-wrapper" data-formjs-question data-surveyjs-external="1">
<div class="surveyjs-answers-wrapper">
<div data-question></div>
<div data-answer>
<input name="surveyjs-answer-external" data-exclude-storage data-field/>
<label>
<span data-label></span>
</label>
</div>
<div data-answer>
<input name="surveyjs-answer-external" data-exclude-storage data-field/>
<label>
<span data-label></span>
</label>
</div>
</div>
</div>
</code></pre>
<p>
Include a bit of HTML code ( see above ), keeping in mind that:
</p>
<ul>
<li class="my-2">
It must be a child of element with attribute <code>data-surveyjs-wrapper</code> ( see <a href="./demos.html">demos</a> )
</li>
<li class="my-2">
Attribute <code>data-surveyjs-external</code> must have an integer number as value ( see example above ). The number is equal to the item position of the external question ( considering only external questions )
</li>
<li class="my-2">
Attribute <code>data-exclude-storage</code> is optional ( used to avoid saving the answer in session storage ) - NOT for <span class="badge badge-pill badge-yellow">Lite</span> version
</li>
</ul>
</div>
</div>
</div>
<!-- JSON File -->
<div id="json-file">
<h3 class="sticky-title">JSON File</h3>
<div class="row">
<div class="col-lg-6">
<p>
Example of JSON file for the survey is <a href="json/survey.json" target="_blank">here</a>.
<br />
During initialization, the survey will fetch data from url passed in <code>options.url</code>.
<br />
The survey will be built if <code>status</code> is "success" and array <code>questions</code> has items.
</p>
<pre class="mh-100">
<code class="language-js">{
"status": "success",
"data": {
"id": 1,
"questions": [
{
"id": "1",
"question": "What's your name?",
"answers": [ { "id": "1", "type": "text", "data": { "subtype": "alphabeticExtended" } } ]
},
{
"id": "1c",
"question": "What's your email address?",
"answers": [
{ "id": "1ca", "type": "email", "placeholder": "address@email.ext" }
],
"errorMessage": "We need your email in case you win :)",
"required": true
},
{
"id": "8",
"question": "What do you like about this survey?",
"answers": [
{ "id": "43", "value": "value-43", "type": "checkbox", "label": "Clear of communication", "sort": 1 },
{ "id": "44", "value": "value-44", "type": "checkbox", "label": "Simplicity of usage", "sort": 2 },
{ "id": "45", "value": "value-45", "type": "checkbox", "label": "Graphic style and language", "sort": 3 },
{ "id": "46", "value": "value-46", "type": "checkbox", "label": "Duration", "sort": 4 }
],
"checks": "[1,2]",
"required": true
}
]
}
}
</code>
</pre>
</div>
<div class="col-lg-6">
<p>
<a href="json/survey.json" target="_blank">JSON file</a> is pretty self explanatory but here you can find a reference for less clear items.
</p>
<p class="m-0">
For each question, each answer in <code>answers</code> will be used to build the HTML field.
<br /><br />
All keys of the object will generate the equivalent HTML attribute ( except for <code>data</code> <code>id</code> <code>label</code> <code>nested</code> <code>related</code> <code>sort</code> ) with the specified value ( in case answer <code>type</code> is equal to "option" or "textarea", also these keys will be ignored for this purpose: <code>type</code> <code>value</code> ).
<br /><br />
All keys in <code>data</code> will generate the equivalent data-attribute <code>data-*</code>.
<br />
In particular, you can use them to enable formJS superpowers ( see <a href="json/survey.json" target="_blank">JSON file</a> and <a href="https://www.valeriodipunzio.com/plugins/formJS/api.html" target="_blank">formJS API</a> for details ), for example:
</p>
<ul class="mb-4">
<li>
<code>subtype</code> to specify a custom validation method
</li>
<li>
<code>validateIfFilled</code> to validate a field only if filled
</li>
</ul>
<p class="m-0">
HTML attribute <code>id</code> is automatically generated like:<br />
<code>`${answerType}-${surveyId}-${questionId}-${answerId}`</code><br />
where:
<br />
</p>
<ul class="mb-4">
<li>
<code>answerType</code> same as <code>type</code> ( if "option", it will be "select" )
</li>
<li>
<code>surveyId</code> the id of the survey. See <code>data.id</code>
</li>
<li>
<code>questionId</code> the id of the question
</li>
<li>
<code>answerId</code> the answer id ( or answer index in case <code>answerType => 'select'</code> )
</li>
</ul>
<p class="m-0">
In case you need, answers can also be "nested" or "related":
</p>
<ul>
<li>
<code>nested</code> when some answers are "grouped" as child ( see key "nested" in <a href="json/survey.json" target="_blank">JSON file</a> )
</li>
<li>
<code>related</code> when an answer, if selected, requires an additional answer ( tipically a radio and an input field - see key "related" in <a href="json/survey.json" target="_blank">JSON file</a> )
</li>
</ul>
<p class="m-0">
You can use these keys on each question object:
</p>
<ul>
<li>
<code>checks</code> ( string ) to enable formJS mutliple-checks validation ( see <a href="https://www.valeriodipunzio.com/plugins/formJS/api.html#builtin-validations" target="_blank">formJS doc</a> )
</li>
<li>
<code>errorMessage</code> ( string | object ) the error message that will be shown to the user if answered is given. It can also be an object to show detailed error messages based on validation rule ( <a href="https://www.valeriodipunzio.com/plugins/formJS/api.html#builtin-errors" target="_blank">formJS doc</a> )
</li>
<li>
<code>required</code> ( boolean ) if the user must give an answer ( if omitted, it will be considered as <code>false</code> )
</li>
<li>
<code>sort</code> ( number ) used to set the order of the questions ( it's also available in answers )
</li>
</ul>
</div>
</div>
</div>
<!-- Initialize -->
<div id="initialize">
<h3 class="sticky-title">Initialize</h3>
<div class="row">
<div class="col-lg-6">
<pre>
<code class="language-js">const $form = document.querySelector('[data-surveyjs-form]');
const options = { url: 'json/survey.json' };
const mySurvey = new Survey( $form, options );
</code></pre>
</div>
<div class="col-lg-6">
<p>
You must specify at least <code>options.url</code> to retrieve the JSON data and build the survey.
</p>
<ul>
<li>
<code>$form</code> ( required ) must be a <u>single form node</u> ( not a nodelist! ) or a <u>CSS string selector</u> <code>const $form = '.my-container .my-form';</code>
</li>
<li>
<code>options</code> ( required ) a JS object as defined in <a href="api.html#options-list">Options section</a> with at least <code>url</code>
</li>
</ul>
<hr />
<p>
You can also access to:
</p>
<ul>
<li>
Survey version: via <code>Survey.prototype.version</code> or <code>$form.surveyjs.version</code>
</li>
<li>
Survey instance: once the instance is created, via <code>$form.surveyjs</code>
</li>
<li>
Survey initialization: boolean via <code>$form.surveyjs.isInitialized</code>
</li>
<li>
Survey data: the survey data structure returned from the AJAX call. Accessible via <code>$form.surveyjs.data</code>
</li>
</ul>
</div>
</div>
</div>
</div>
<footer class="text-center mt-5 pt-5 mb-3">
<hr />
<p class="small m-0">
Made with passion by <a href="https://valeriodipunzio.com" target="_blank">Valerio Di Punzio</a>
</p>
</footer>
</div>
</body>
</html>