-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-started.html
executable file
·270 lines (249 loc) · 13.6 KB
/
get-started.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Get Started | formJS - JavaScript Form Validation. Made Easy</title>
<meta name="description" content="JavaScript Form Validation. Made Easy">
<meta name="keywords" content="form, validation, javascript, plugin">
<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/doc.css">
<link rel="stylesheet" href="css/prism.css">
<script defer src="js/prism.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">f</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/formJS" 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/formJS" target="_blank">View on Github</a>
<a class="dropdown-item" href="https://github.com/SimplySayHi/formJS/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">formJS</h4>
<h1 class="border-0 m-0">Get Started</h1>
<!-- Install -->
<div id="install">
<h3 class="sticky-title">Install</h3>
<div class="row justify-content-between">
<div class="col-lg-5">
<p>
Include the library script in your page:
</p>
<pre>
<code class="language-html"><script src="https://unpkg.com/formjs-plugin@5"></script>
</code></pre>
<pre>
<code class="language-html"><script src="https://cdn.jsdelivr.net/gh/simplysayhi/formJS@5/dist/formjs.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
</code></pre>
<pre>
<code class="language-js">import Form from 'formjs-plugin'
</code></pre>
</div>
</div>
<hr />
<p>
You can also import <span class="badge badge-pill badge-yellow">Lite</span> version and some extras, for example:
</p>
<code>import Form from 'formjs-plugin/lite'</code>
<br />
<code>import { username } from 'formjs-plugin/additional-rules'</code>
<br />
<code>import { username } from 'formjs-plugin/additional-errors'</code>
<br />
<code>import { initCharLengthFields } from 'formjs-plugin/utils'</code>
<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 example of HTML structure to make the validation works.
<br />
formJS uses default HTML attributes to:
</p>
<ul>
<li>
setup some instance options
</li>
<li>
enable JS validation
</li>
</ul>
<pre>
<code class="language-html"><form action="/mypath/mypage.php" method="POST" novalidate name="my-form-example">
<!-- BASIC TEXT INPUT -->
<div data-formjs-question>
<label>Name</label>
<input type="text" name="myName" />
</div>
<!-- REQUIRED FIELD WITH HTML STANDARD TYPE ( EMAIL ) -->
<div data-formjs-question>
<label>Email</label>
<input type="email" name="myEmail" required />
</div>
<!-- REQUIRED FIELD WITH CUSTOM VALIDATION ( FISCAL CODE ) -->
<div data-formjs-question>
<label>Fiscal Code</label>
<input type="text" data-subtype="fiscal-code" name="myFiscalCode" required />
</div>
<button type="submit">SEND</button>
</form>
</code></pre>
</div>
<div class="col-lg-6">
<p>
Some notes about form attributes <span class="small">( if set, they will replace options passed to the constructor function )</span>:
</p>
<ul>
<li class="my-2">
<code>action</code> will be set as <code>options.formOptions.ajaxOptions.url</code>
</li>
<li class="my-2">
<code>enctype</code> will be set as <code>options.formOptions.ajaxOptions.headers['Content-Type']</code> ( not for <code>multipart/form-data</code> where enctype will just allow data transformation to <code>FormData</code> )
</li>
<li class="my-2">
<code>method</code> will be set as <code>options.formOptions.ajaxOptions.method</code>
</li>
</ul>
<p>
Some notes about field attributes:
</p>
<ul>
<li class="my-2">
<code>data-formjs-question</code> ( optional | empty attribute ) used for visual feedback on valid / invalid / dirty fields ( to be used on a container element of a question ).<br />
Can be changed via <code>questionContainer</code> in <a href="api.html#field-options">Field Options</a>.
</li>
<li class="my-2">
<code>name</code> ( required ) used inside "getFormData" method to collect form data.
</li>
<li class="my-2">
<code>required</code> mandatory for fields that require an answer.
</li>
<li class="my-2">
<code>type</code> ( required ) used for field validation.
</li>
<li class="my-2">
<code>data-type</code> ( optional ) by now only "number" is supported. See "strictHtmlValidation" option in <a href="api.html#field-options">Field Options</a> section for details.
</li>
<li class="my-2">
<code>data-subtype</code> ( optional ) for custom validations ( eg: VAT number, fiscal code, etc - see the <a href="api.html#builtin-validations">full list</a> ).
</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('form');
const options = {...};
const formInstance = new Form( $form, options );
</code></pre>
</div>
<div class="col-lg-6">
<ul>
<li>
<code>$form</code> ( required ) must be a <u>single form node</u> ( not a nodelist! ) or a <u>CSS string selector</u>
</li>
<li>
<code>options</code> ( optional ) a JS object with fieldOptions and formOptions ( see <a href="api.html#options-list">Options section</a> ).
</li>
</ul>
<hr />
<p class="mb-0">
Thanks to initialization, these will then run automatically ( NOT for <span class="badge badge-pill badge-yellow">Lite</span> version ):
</p>
<ul>
<li>
Fields validation: on events defined in <code>options.fieldOptions.validateOnEvents</code> ( see <a href="api.html#field-options">Field Options section</a> )
</li>
<li>
Form submit: on submit event, if form is valid ( form is validated via method <code>validateForm</code> - see <a href="api.html#methods">Methods section</a> ). By default, for is submitted via ajax with options from <code>options.formOptions.ajaxOptions</code>
</li>
</ul>
<hr />
<p class="mb-0">
You can also access to:
</p>
<ul>
<li>
Form version: via <code>Form.prototype.version</code> or <code>$form.formjs.version</code>
</li>
</ul>
<hr />
<p>
<a href="demos.html">See demos</a>
</p>
</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>