Skip to content

Commit c981148

Browse files
committed
readme wip...
1 parent 9cd4d5e commit c981148

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

README.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
The goal of this project is to create a feature rich jQuery plugin used for validating form data and that
2-
keeps the HTML code clean from javascript logic. Even though the plugin has **a wide range of validation functions**
3-
it's going to be suitable for **mobile websites**. This is achieved by grouping together functions in "modules", making
4-
it possible for the programmer to load **only those function that's needed** to validate a particular form.
5-
61

2+
The goal of this project is to create a feature rich jQuery plugin used for validating form data and that
3+
keeps the HTML code clean from javascript logic. Even though the plugin has **a wide range of validation functions**
4+
it's designed to consume the least amount bandwidth as possible (which makes it very suitable for **mobile websites**).
5+
This is achieved by grouping together functions in "modules", making it possible for the programmer
6+
to load **only those functions that's needed** to validate a particular form.
77

88
*Usage example*
99

@@ -37,7 +37,7 @@ it possible for the programmer to load **only those function that's needed** to
3737
```
3838

3939
## Features
40-
### Default validators
40+
### Default validators (no module needed)
4141
* **validate_url**
4242
* **validate_email**
4343
* **validate_domain***domain.com*
@@ -62,18 +62,24 @@ it possible for the programmer to load **only those function that's needed** to
6262
### Module: sweden
6363
* **validate_swemob***validate that the value is a swedish mobile telephone number*
6464
* **validate_swesec***validate swedish social security number*
65+
* **validate_county** - *validate that the value is an existing county in Sweden*
66+
* **validate_municipality** - *validate that the value is an existing municipality in Sweden*
6567

6668
### Module: ukvat
6769
* **validate_ukvatnumber**
6870

6971
### Misc (part of core)
7072
* Show help information automatically when input is focused
7173
* Validate given values immediately when input is blurred.
74+
* Make validation optional by adding attribute data-validation-optional="true" to the element. This means
75+
that the validation defined in data-validation only will take place in case a value is given.
76+
* Make validation dependent on another input of type checkbox being checked by adding attribute
77+
data-validation-if-checked="name of checkbox input"
7278

7379

7480
## Writing a custom validator
7581
You can use the function `$.formUtils.addValidator()` to add your own validation function. Here's an example of a validator
76-
that checks if the input contains an even number
82+
that checks if the input contains an even number.
7783

7884
```html
7985
<html>
@@ -103,11 +109,12 @@ that checks if the input contains an even number
103109

104110
*name* - The name of the validator, which is used in the validation attribute of the input element.
105111

106-
*validate* - callback function that validates the input.
112+
*validate* - Callback function that validates the input. Should return a boolean telling if the value is considered valid or not.
107113

108-
*errorMessageKey* - Name of language property that is used in case the value of the input is invalid
114+
*errorMessageKey* - Name of language property that is used in case the value of the input is invalid.
109115

110-
*errorMessage* - An alternative error message that is used if errorMessageKey is left with an empty value
116+
*errorMessage* - An alternative error message that is used if errorMessageKey is left with an empty value or isn't defined
117+
in the language object. Note that you also can use [inline error messages](#localization) in your form.
111118

112119

113120
The validation function takes these five arguments:
@@ -141,7 +148,7 @@ It is now possible to show that the value of an input is incorrect immediately w
141148
```
142149

143150
## Show help information
144-
Since version 1.1 it is possible to display help information for each input. The information will fade in when input is focused and fade out when input is blurred.
151+
It is possible to display help information for each input. The information will fade in when input is focused and fade out when input is blurred.
145152

146153
```html
147154
<form action="" onsubmit="return $(this).validate();" id="my_form">
@@ -205,10 +212,13 @@ $('#my_form')
205212
```
206213

207214
## Localization
208-
All error dialogs can be overwritten by passing an object into the validation function.
215+
This plugin contains a set of error dialogs. In case you don't define an inline error message the plugin
216+
will fall back on one of the dialogs below. You can how ever add the attribute *data-validation-error-msg* to an
217+
element, and that message will be displayed instead. All error dialogs can be overwritten by passing an
218+
object into the validation function.
209219

210220
```javascript
211-
var jQueryFormLang = {
221+
var enErrorDialogs = {
212222
errorTitle : 'Form submission failed!',
213223
requiredFields : 'You have not answered all required fields',
214224
badTime : 'You have not given a correct time',
@@ -228,7 +238,9 @@ var jQueryFormLang = {
228238
badCustomVal : 'You gave an incorrect answer',
229239
badInt : 'Incorrect integer value',
230240
badSecurityNumber : 'Your social security number was incorrect',
231-
badUKVatAnswer : 'Incorrect UK VAT Number'
241+
badUKVatAnswer : 'Incorrect UK VAT Number',
242+
badNumberOfSelectedOptionsStart : 'You have to choose at least ',
243+
badNumberOfSelectedOptionsEnd : ' answers'
232244
};
233245
```
234246

@@ -241,7 +253,7 @@ var jQueryFormLang = {
241253
<head>
242254
<body>
243255
...
244-
<form action="script.php" onsubmit="return $(this).validate(jQueryFormLang);">
256+
<form action="script.php" onsubmit="return $(this).validate(enErrorDialogs);">
245257
...
246258
```
247259

0 commit comments

Comments
 (0)