Skip to content

Commit 561822c

Browse files
committed
Added events beforeValidation and validation victorjonsson#66
1 parent 54c6e5c commit 561822c

File tree

10 files changed

+35
-19
lines changed

10 files changed

+35
-19
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ it calls jQ func **$.formUtils.validateInput** to validate the single input when
294294

295295
## Changelog
296296

297+
#### 2.1....
298+
* General improvements and bug fixes
299+
* Added events "beforeValidation" and "validation" (see http://formvalidator.net/#configuration_callbacks for more info)
297300

298301
#### 2.1.27
299302
* E-mail validation support .eu top domain

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.1.32
13+
* @version 2.1.33
1414
*/
1515
(function($) {
1616

form-validator/file.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.1.32
13+
* @version 2.1.33
1414
*/
1515
(function($, window) {
1616

form-validator/form-test.html

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,43 +51,43 @@
5151
<form action="" id="test-form" role="form">
5252
<div class="form-group">
5353
<label class="control-label" for="inline-suggestions">Inline suggestions</label>
54-
<input type="text" id="inline-suggestions" class="form-control" data-suggestions="Monkey, Horse, Fox, Tiger, Elephant" />
54+
<input name="inline suggestions" type="text" id="inline-suggestions" class="form-control" data-suggestions="Monkey, Horse, Fox, Tiger, Elephant" />
5555
</div>
5656

5757
<div class="form-group">
5858
<label class="control-label" for="country-suggestions">Country suggestions</label>
59-
<input type="text" id="country-suggestions" class="form-control" />
59+
<input name="country suggestions" type="text" id="country-suggestions" class="form-control" />
6060
</div>
6161

6262
<div class="form-group">
6363
<label class="control-label" for="country-suggestions">Swedish county suggestions</label>
64-
<input type="text" id="swedish-county-suggestions" class="form-control" />
64+
<input name="Swedish county suggestion" type="text" id="swedish-county-suggestions" class="form-control" />
6565
</div>
6666

6767
<div class="form-group password-strength">
6868
<label class="control-label" for="password">Display password strength (only strong)</label>
69-
<input type="password" id="password" class="form-control" data-validation="strength" data-validation-strength="3" />
69+
<input name="password" type="password" id="password" class="form-control" data-validation="strength" data-validation-strength="3" />
7070
</div>
7171

7272
<div class="form-group">
7373
<label class="control-label">Alphanumeric and -_ and spaces</label>
74-
<input class="form-control" name="test" data-validation="alphanumeric" data-validation-allowing="-_ " />
74+
<input name="alphanumeric with spaces" class="form-control" name="test" data-validation="alphanumeric" data-validation-allowing="-_ " />
7575
</div>
7676

7777
<div class="form-group">
7878
<label class="control-label">Alphanumeric only</label>
79-
<input class="form-control" name="test2" data-validation="alphanumeric" />
79+
<input name="aplhanumeric only" class="form-control" name="test2" data-validation="alphanumeric" />
8080
</div>
8181

8282
<div class="checkbox">
8383
<label>
84-
<input type="checkbox" data-validation="required" /> Must be checked
84+
<input name="checkbox" type="checkbox" data-validation="required" /> Must be checked
8585
</label>
8686
</div>
8787

8888
<div class="form-group">
8989
<label class="control-label">Even numbers only</label>
90-
<input class="form-control" name="test4" data-validation="even_number" />
90+
<input name="even numbers" class="form-control" name="test4" data-validation="even_number" />
9191
</div>
9292

9393
<div class="form-group">
@@ -100,7 +100,7 @@
100100

101101
<div class="form-group">
102102
<label class="control-label">File validation</label>
103-
<input type="file" name="some-file" class="form-control"
103+
<input type="file" name="some-file1" class="form-control"
104104
data-validation="size mime required"
105105
data-validation-error-msg="You must upload an image file"
106106
data-validation-allowing="jpg, png, ico"
@@ -109,7 +109,7 @@
109109

110110
<div class="form-group">
111111
<label class="control-label">File validation (multiple)</label>
112-
<input type="file" multiple="multiple" name="some-file" class="form-control"
112+
<input type="file" multiple="multiple" name="some-file2" class="form-control"
113113
data-validation="size mime required length"
114114
data-validation-length="min2"
115115
data-validation-error-msg="You must upload at least two image files"
@@ -209,6 +209,13 @@
209209
// Load one module outside $.validate() even though you do not have to
210210
$.formUtils.loadModules('date'+dev+'.js', false, false);
211211

212+
$('input')
213+
.on('beforeValidation', function() {
214+
console.log('About to validate input "'+this.name+'"');
215+
})
216+
.on('validation', function(evt, isValid) {
217+
console.log('Input '+this.name+' is '+( isValid ? 'VALID':'NOT VALID'));
218+
});
212219

213220
})(jQuery, window);
214221
</script>

form-validator/jquery.form-validator.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @website http://formvalidator.net/
77
* @license Dual licensed under the MIT or GPL Version 2 licenses
8-
* @version 2.1.32
8+
* @version 2.1.33
99
*/
1010
(function($) {
1111

@@ -133,6 +133,8 @@
133133

134134
var validation = $.formUtils.validateInput($element, language, config, $form, eventContext);
135135

136+
$element.trigger('validation', [validation===true]);
137+
136138
if(validation === true) {
137139
$element
138140
.addClass('valid')
@@ -269,6 +271,8 @@
269271
'submit'
270272
);
271273

274+
$element.trigger('validation', [validation===true]);
275+
272276
if(validation !== true) {
273277
addErrorMessage(validation, $element);
274278
} else {
@@ -719,6 +723,8 @@
719723
*/
720724
validateInput : function($element, language, config, $form, eventContext) {
721725

726+
$element.trigger('beforeValidation');
727+
722728
var value = $.trim( $element.val() || ''),
723729
optional = $element.valAttr('optional'),
724730

form-validator/jquery.form-validator.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/location.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.1.32
13+
* @version 2.1.33
1414
*/
1515
(function($) {
1616

form-validator/security.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @website http://formvalidator.net/#security-validators
1414
* @license Dual licensed under the MIT or GPL Version 2 licenses
15-
* @version 2.1.32
15+
* @version 2.1.33
1616
*/
1717
(function($) {
1818

form-validator/sweden.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @website http://formvalidator.net/#swedish-validators
1515
* @license Dual licensed under the MIT or GPL Version 2 licenses
16-
* @version 2.1.32
16+
* @version 2.1.33
1717
*/
1818
(function($, window) {
1919

form-validator/uk.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @website http://formvalidator.net/#uk-validators
1111
* @license Dual licensed under the MIT or GPL Version 2 licenses
12-
* @version 2.1.32
12+
* @version 2.1.33
1313
*/
1414
$.formUtils.addValidator({
1515
name : 'ukvatnumber',

0 commit comments

Comments
 (0)