Skip to content

Commit fa537fe

Browse files
committed
Add a description for the bootstrap-form
1 parent 6120b08 commit fa537fe

1 file changed

Lines changed: 389 additions & 0 deletions

File tree

Bootstrap/bootstrap-form/README.md

Lines changed: 389 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,389 @@
1+
# Form validator plugin for Bootstrap #
2+
3+
This plugin verifies if the user doesn't write errors in the form field according to the Bootstrap styles.
4+
The form rules are defined with the HTML5 specifications.
5+
6+
Here is an example which shows a form with all input types.
7+
8+
Installation
9+
------------
10+
11+
First, to make it works, the following files have to be included.
12+
13+
<pre>
14+
&lt;link href=&quot;bootstrap-default.css&quot; rel=&quot;stylesheet&quot;&gt;
15+
&lt;link href=&quot;bootstrap-responsive.css&quot; rel=&quot;stylesheet&quot;&gt;
16+
&lt;link href=&quot;bootstrap-form.css&quot; rel=&quot;stylesheet&quot;&gt;
17+
&lt;script src=&quot;jquery.js&quot;&gt; &lt;/script&gt;
18+
&lt;script src=&quot;bootstrap-tooltip.js&quot;&gt; &lt;/script&gt;
19+
&lt;script src=&quot;bootstrap-form.js&quot;&gt; &lt;/script&gt;
20+
</pre>
21+
*Note : Files `bootstrap-form.css` and `bootstrap-form.js` are part of the plugin.*
22+
23+
Launching
24+
---------
25+
26+
Next, the form validator plugin must launch.
27+
28+
<pre>
29+
&lt;script type=&quot;text/javascript&quot;&gt;
30+
$(document).ready(function() {
31+
$('form').form();
32+
});
33+
&lt;/script&gt;
34+
</pre>
35+
36+
It is possible to specify options when the form is launched :
37+
* asterisk, boolean which print or not the asterisk for obligatory field, `true` ;
38+
* asteriskContent, string which is the asterisk content, `<span class='help-inline'>*</span>`.
39+
40+
Example
41+
-------
42+
43+
To finish, in first part, here is a screen for a form example.
44+
45+
![](https://github.com/ObjetDirect/javascript/raw/master/Bootstrap/bootstrap-form/example.png)
46+
47+
And, in second part, the form body with all HTML5 input types which built this example.
48+
49+
<pre>
50+
&lt;form class=&quot;form form-horizontal&quot; action=&quot;./&quot;&gt;
51+
</pre>
52+
53+
<pre>
54+
&lt;fieldset class=&quot;well&quot;&gt;
55+
&lt;h3&gt;Connection informations&lt;/h3&gt;
56+
&lt;br/&gt;
57+
</pre>
58+
59+
**Input text**
60+
61+
<pre>
62+
&lt;div class=&quot;control-group&quot;&gt;
63+
&lt;label class=&quot;control-label&quot; for=&quot;inputLogin&quot;&gt;Login&lt;/label&gt;
64+
&lt;div class=&quot;controls&quot;&gt;
65+
&lt;input type=&quot;text&quot; id=&quot;inputLogin&quot; class=&quot;input-medium&quot; required=&quot;required&quot;
66+
pattern=&quot;[A-Za-z0-9]*&quot; data-error=&quot;Please give a correct login.&quot;&gt;
67+
&lt;/div&gt;
68+
&lt;/div&gt;
69+
</pre>
70+
If the user doesn't want to show an error on this input,
71+
72+
- he mustn't let the empty field `required="required"` ;
73+
- he has to write letters or numbers `pattern="[A-Za-z0-9]*"`.
74+
75+
Else, the error defined with `data-error="Please give a correct login."` appears.
76+
77+
**Input password**
78+
79+
<pre>
80+
&lt;div class=&quot;control-group&quot;&gt;
81+
&lt;label class=&quot;control-label&quot; for=&quot;inputPassword&quot;&gt;Password&lt;/label&gt;
82+
&lt;div class=&quot;controls&quot;&gt;
83+
&lt;input type=&quot;password&quot; id=&quot;inputPassword&quot; class=&quot;input-medium&quot; required=&quot;required&quot;
84+
data-error=&quot;Please give a correct password.&quot;&gt;
85+
&lt;/div&gt;
86+
&lt;/div&gt;
87+
</pre>
88+
If the user doesn't want to show an error on this input,
89+
90+
- he mustn't let the empty field `required="required"`.
91+
92+
Else, the error defined with `data-error="Please give a correct password."` appears.
93+
94+
**Input email**
95+
96+
<pre>
97+
&lt;div class=&quot;control-group&quot;&gt;
98+
&lt;label class=&quot;control-label&quot; for=&quot;inputEmail&quot;&gt;E-mail address&lt;/label&gt;
99+
&lt;div class=&quot;controls&quot;&gt;
100+
&lt;input type=&quot;email&quot; id=&quot;inputEmail&quot; class=&quot;input-medium&quot; required=&quot;required&quot;
101+
data-error=&quot;Please give a correct e-mail address.&quot;&gt;
102+
&lt;/div&gt;
103+
&lt;/div&gt;
104+
</pre>
105+
If the user doesn't want to show an error on this input,
106+
107+
- he has to write the email format `type="email"` ;
108+
- he mustn't let the empty field `required="required"`.
109+
110+
Else, the error defined with `data-error="Please give a correct e-mail address."` appears.
111+
112+
<pre>
113+
&lt;/fieldset&gt;
114+
&lt;fieldset class=&quot;well&quot;&gt;
115+
&lt;h3&gt;General informations&lt;/h3&gt;
116+
&lt;br/&gt;
117+
</pre>
118+
119+
**Input radio**
120+
121+
<pre>
122+
&lt;div class=&quot;control-group&quot;&gt;
123+
&lt;label class=&quot;control-label&quot; for=&quot;inputGender&quot;&gt;Gender&lt;/label&gt;
124+
&lt;div class=&quot;controls radio input-mini&quot;&gt;
125+
&lt;input type=&quot;radio&quot; value=&quot;Man&quot; id=&quot;man&quot; name=&quot;gender&quot; required=&quot;required&quot;
126+
data-error=&quot;Please check a gender.&quot;&gt;
127+
&lt;label for=&quot;man&quot;&gt;Man&lt;/label&gt;
128+
&lt;/div&gt;
129+
&lt;div class=&quot;controls radio input-mini&quot;&gt;
130+
&lt;input type=&quot;radio&quot; value=&quot;Woman&quot; id=&quot;woman&quot; name=&quot;gender&quot;&gt;
131+
&lt;label for=&quot;woman&quot;&gt;Woman&lt;/label&gt;
132+
&lt;/div&gt;
133+
&lt;/div&gt;
134+
</pre>
135+
If the user doesn't want to show an error on this input,
136+
137+
- he has to check one of all inputs `required="required"`.
138+
139+
Else, the error defined with `data-error="Please check a gender."` appears.
140+
141+
**Input date**
142+
143+
<pre>
144+
&lt;div class=&quot;control-group&quot;&gt;
145+
&lt;label class=&quot;control-label&quot; for=&quot;inputAge&quot;&gt;Birth date&lt;/label&gt;
146+
&lt;div class=&quot;controls&quot;&gt;
147+
&lt;input type=&quot;date&quot; id=&quot;inputAge&quot; class=&quot;input-medium&quot; required=&quot;required&quot;
148+
data-error=&quot;Please give a correct birth date.&quot;&gt;
149+
&lt;/div&gt;
150+
&lt;/div&gt;
151+
</pre>
152+
If the user doesn't want to show an error on this input,
153+
154+
- he has to write the date format `type="date"` ;
155+
- he mustn't let the empty field `required="required"`.
156+
157+
Else, the error defined with `data-error="Please give a correct birth date."` appears.
158+
159+
**TextArea**
160+
161+
<pre>
162+
&lt;div class=&quot;control-group&quot;&gt;
163+
&lt;label class=&quot;control-label&quot; for=&quot;inputLocation&quot;&gt;Locality&lt;br/&gt;ZIP&lt;br/&gt;City&lt;/label&gt;
164+
&lt;div class=&quot;controls&quot;&gt;
165+
&lt;textarea id=&quot;inputLocation&quot; class=&quot;input-medium&quot; rows=&quot;3&quot;&gt;&lt;/textarea&gt;
166+
&lt;/div&gt;
167+
&lt;/div&gt;
168+
</pre>
169+
The user never watch errors on this input.
170+
171+
**Input tel**
172+
173+
<pre>
174+
&lt;div class=&quot;control-group&quot;&gt;
175+
&lt;label class=&quot;control-label&quot; for=&quot;inputTel&quot;&gt;Phone&lt;/label&gt;
176+
&lt;div class=&quot;controls&quot;&gt;
177+
&lt;input type=&quot;tel&quot; id=&quot;inputTel&quot; class=&quot;input-medium&quot; pattern=&quot;[0-9]{10}&quot;
178+
data-error=&quot;Please give a correct phone number.&quot;&gt;
179+
&lt;/div&gt;
180+
&lt;/div&gt;
181+
</pre>
182+
If the user doesn't want to show an error on this input,
183+
184+
- he has to write the telephone number format `type="tel"`.
185+
186+
Else, the error defined with `data-error="Please give a correct phone number."` appears.
187+
188+
**Input url**
189+
190+
<pre>
191+
&lt;div class=&quot;control-group&quot;&gt;
192+
&lt;label class=&quot;control-label&quot; for=&quot;inputWeb&quot;&gt;Website&lt;/label&gt;
193+
&lt;div class=&quot;controls&quot;&gt;
194+
&lt;input type=&quot;url&quot; id=&quot;inputWeb&quot; class=&quot;input-medium&quot; placeholder=&quot;http://&quot;
195+
data-error=&quot;Please give a correct website url.&quot;&gt;
196+
&lt;/div&gt;
197+
&lt;/div&gt;
198+
</pre>
199+
If the user doesn't want to show an error on this input,
200+
201+
- he has to write the website url format `type="url"`.
202+
203+
Else, the error defined with `data-error="Please give a correct website url."` appears.
204+
205+
**Input file**
206+
207+
<pre>
208+
&lt;div class=&quot;control-group&quot;&gt;
209+
&lt;label class=&quot;control-label&quot; for=&quot;inputImage&quot;&gt;Personal image&lt;/label&gt;
210+
&lt;div class=&quot;controls&quot;&gt;
211+
&lt;input type=&quot;file&quot; id=&quot;inputImage&quot; class=&quot;input-xlarge&quot; accept=&quot;image/jpeg, image/png&quot;
212+
required=&quot;required&quot;
213+
data-error=&quot;Please give an image with jpg or png format.&quot;&gt;
214+
&lt;/div&gt;
215+
&lt;/div&gt;
216+
</pre>
217+
If the user doesn't want to show an error on this input,
218+
219+
- he has to choose good files `type="file"` and `accept="image/jpeg, image/png"` ;
220+
- he mustn't let the empty field `required="required"`.
221+
222+
Else, the error defined with `data-error="Please give an image with jpg or png format."` appears.
223+
224+
<pre>
225+
&lt;/fieldset&gt;
226+
&lt;fieldset class=&quot;well&quot;&gt;
227+
&lt;h3&gt;Optional informations&lt;/h3&gt;
228+
&lt;br/&gt;
229+
</pre>
230+
231+
**Input number**
232+
233+
<pre>
234+
&lt;div class=&quot;control-group&quot;&gt;
235+
&lt;label class=&quot;control-label&quot; for=&quot;inputComputer&quot;&gt;Computers number&lt;/label&gt;
236+
&lt;div class=&quot;controls&quot;&gt;
237+
&lt;input type=&quot;number&quot; value=&quot;0&quot; min=&quot;0&quot; max=&quot;10&quot; id=&quot;inputComputer&quot; class=&quot;input-medium&quot;
238+
data-error=&quot;Please give a correct computers number.&quot;&gt;
239+
&lt;/div&gt;
240+
&lt;/div&gt;
241+
</pre>
242+
If the user doesn't want to show an error on this input,
243+
244+
- he has to choose good number `type="number"`, `min="0"` and `max="10"`.
245+
246+
Else, the error defined with `data-error="Please give a correct computers number."` appears.
247+
248+
**Input search**
249+
250+
<pre>
251+
&lt;div class=&quot;control-group&quot;&gt;
252+
&lt;label class=&quot;control-label&quot; for=&quot;inputSearch&quot;&gt;Favorite animal&lt;/label&gt;
253+
&lt;div class=&quot;controls&quot;&gt;
254+
&lt;input type=&quot;search&quot; id=&quot;inputSearch&quot; list=&quot;inputSearchList&quot; class=&quot;input-medium&quot;&gt;
255+
&lt;datalist id=&quot;inputSearchList&quot;&gt;
256+
&lt;option value=&quot;Alligator&quot;&gt;
257+
&lt;option value=&quot;Bear&quot;&gt;
258+
&lt;option value=&quot;Cat&quot;&gt;
259+
&lt;option value=&quot;Dolphin&quot;&gt;
260+
&lt;option value=&quot;Elephant&quot;&gt;
261+
&lt;option value=&quot;Fawn&quot;&gt;
262+
&lt;option value=&quot;Gazelle&quot;&gt;
263+
&lt;/datalist&gt;
264+
&lt;/div&gt;
265+
&lt;/div&gt;
266+
</pre>
267+
The user never watch errors on this input.
268+
269+
**Select multiple**
270+
271+
<pre>
272+
&lt;div class=&quot;control-group&quot;&gt;
273+
&lt;label class=&quot;control-label&quot; for=&quot;inputFruit&quot;&gt;Favorite fruit&lt;br/&gt;(between 2 and 4)&lt;/label&gt;
274+
&lt;div class=&quot;controls&quot;&gt;
275+
&lt;select id=&quot;inputFruit&quot; class=&quot;input-medium&quot; multiple=&quot;multiple&quot; data-min=&quot;2&quot; data-max=&quot;4&quot;
276+
data-error=&quot;Please choose between two and four fruits.&quot;&gt;
277+
&lt;option value=&quot;apple&quot;&gt;Apple&lt;/option&gt;
278+
&lt;option value=&quot;banana&quot;&gt;Banana&lt;/option&gt;
279+
&lt;option value=&quot;cherry&quot;&gt;Cherry&lt;/option&gt;
280+
&lt;option value=&quot;dewberry&quot;&gt;Dewberry&lt;/option&gt;
281+
&lt;option value=&quot;elderberry&quot;&gt;Elderberry&lt;/option&gt;
282+
&lt;option value=&quot;fig&quot;&gt;Fig&lt;/option&gt;
283+
&lt;option value=&quot;grape&quot;&gt;Grape&lt;/option&gt;
284+
&lt;/select&gt;
285+
&lt;/div&gt;
286+
&lt;/div&gt;
287+
</pre>
288+
If the user doesn't want to show an error on this input,
289+
290+
- he has to choose the asked number of all inputs `data-min="2"` and `data-min="4"`.
291+
292+
Else, the error defined with `data-error="Please choose between two and four fruits."` appears.
293+
294+
*Note : Tags `data-min` and `data-min` are specific tags for the form validator plugin.
295+
They impose a limit when the user has to make a multiple choice.*
296+
297+
**Input checkbox**
298+
299+
<pre>
300+
&lt;div class=&quot;control-group&quot;&gt;
301+
&lt;label class=&quot;control-label&quot; for=&quot;inputBrowser&quot;&gt;Favorite browser&lt;br/&gt;(at least 1)&lt;/label&gt;
302+
&lt;div class=&quot;controls checkbox input-mini&quot;&gt;
303+
&lt;input type=&quot;checkbox&quot; value=&quot;Chrome&quot; id=&quot;chrome&quot; name=&quot;browser[]&quot; data-min=&quot;1&quot;
304+
data-error=&quot;Please check at least one browser.&quot;&gt;
305+
&lt;label for=&quot;chrome&quot;&gt;Chrome&lt;/label&gt;
306+
&lt;/div&gt;
307+
&lt;div class=&quot;controls checkbox input-mini&quot;&gt;
308+
&lt;input type=&quot;checkbox&quot; value=&quot;Firefox&quot; id=&quot;firefox&quot; name=&quot;browser[]&quot;&gt;
309+
&lt;label for=&quot;firefox&quot;&gt;Firefox&lt;/label&gt;
310+
&lt;/div&gt;
311+
&lt;div class=&quot;controls checkbox input-mini&quot;&gt;
312+
&lt;input type=&quot;checkbox&quot; value=&quot;IExplorer&quot; id=&quot;iexplorer&quot; name=&quot;browser[]&quot;&gt;
313+
&lt;label for=&quot;iexplorer&quot;&gt;IExplorer&lt;/label&gt;
314+
&lt;/div&gt;
315+
&lt;div class=&quot;controls checkbox input-mini&quot;&gt;
316+
&lt;input type=&quot;checkbox&quot; value=&quot;Opera&quot; id=&quot;opera&quot; name=&quot;browser[]&quot;&gt;
317+
&lt;label for=&quot;opera&quot;&gt;Opera&lt;/label&gt;
318+
&lt;/div&gt;
319+
&lt;div class=&quot;controls checkbox input-mini&quot;&gt;
320+
&lt;input type=&quot;checkbox&quot; value=&quot;Safari&quot; id=&quot;safari&quot; name=&quot;browser[]&quot;&gt;
321+
&lt;label for=&quot;safari&quot;&gt;Safari&lt;/label&gt;
322+
&lt;/div&gt;
323+
&lt;/div&gt;
324+
</pre>
325+
If the user doesn't want to show an error on this input,
326+
327+
- he has to check the asked number of all inputs `data-min="1"` (see **Select Multiple**).
328+
329+
Else, the error defined with `data-error="Please check at least one browser."` appears.
330+
331+
**Input color**
332+
333+
<pre>
334+
&lt;div class=&quot;control-group&quot;&gt;
335+
&lt;label class=&quot;control-label&quot; for=&quot;inputColor&quot;&gt;Favorite color&lt;/label&gt;
336+
&lt;div class=&quot;controls&quot;&gt;
337+
&lt;input type=&quot;color&quot; id=&quot;inputColor&quot; class=&quot;input-medium&quot;&gt;
338+
&lt;/div&gt;
339+
&lt;/div&gt;
340+
</pre>
341+
The user never watch errors on this input.
342+
343+
**Select**
344+
345+
<pre>
346+
&lt;div class=&quot;control-group&quot;&gt;
347+
&lt;label class=&quot;control-label&quot; for=&quot;inputOS&quot;&gt;Favorite OS&lt;/label&gt;
348+
&lt;div class=&quot;controls&quot;&gt;
349+
&lt;select id=&quot;inputOS&quot; class=&quot;input-medium&quot;&gt;
350+
&lt;option&gt;Nothing&lt;/option&gt;
351+
&lt;option&gt;Linux&lt;/option&gt;
352+
&lt;option&gt;Mac&lt;/option&gt;
353+
&lt;option&gt;Windows&lt;/option&gt;
354+
&lt;/select&gt;
355+
&lt;/div&gt;
356+
&lt;/div&gt;
357+
</pre>
358+
The user never watch errors on this input.
359+
360+
**Input range**
361+
362+
<pre>
363+
&lt;div class=&quot;control-group&quot;&gt;
364+
&lt;label class=&quot;control-label&quot; for=&quot;inputNote&quot;&gt;Note&lt;/br&gt;(on 20)&lt;/label&gt;
365+
&lt;div class=&quot;controls&quot;&gt;
366+
&lt;input type=&quot;range&quot; max=&quot;20&quot; id=&quot;inputNote&quot; class=&quot;input-medium&quot;&gt;
367+
&lt;/div&gt;
368+
&lt;/div&gt;
369+
</pre>
370+
The user never watch errors on this input.
371+
372+
<pre>
373+
&lt;/fieldset&gt;
374+
</pre>
375+
376+
**Input button**
377+
378+
<pre>
379+
&lt;div class=&quot;form-actions&quot;&gt;
380+
&lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Submit&lt;/button&gt;
381+
&lt;input type=&quot;reset&quot; class=&quot;btn&quot; value=&quot;Cancel&quot;&gt;
382+
&lt;/div&gt;
383+
</pre>
384+
When the user submit the form whereas fields are empty, the request is not sent and the errors printed.
385+
If he clicks on Cancel, the form resets like to the beginning.
386+
387+
<pre>
388+
&lt;/form&gt;
389+
</pre>

0 commit comments

Comments
 (0)