Skip to content

Commit 012d0e4

Browse files
committed
Added callback onValidate
1 parent 5b0e934 commit 012d0e4

File tree

9 files changed

+50
-22
lines changed

9 files changed

+50
-22
lines changed

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* @license Dual licensed under the MIT or GPL Version 2 licenses
15-
* @version 1.9.34
15+
* @version 1.9.35
1616
*/
1717
(function($) {
1818

form-validator/jquery.form-validator.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Documentation and issue tracking on Github <https://github.com/victorjonsson/jQuery-Form-Validator/>
66
*
77
* @license Dual licensed under the MIT or GPL Version 2 licenses
8-
* @version 1.9.34
8+
* @version 1.9.35
99
*/
1010
(function($) {
1111

@@ -194,11 +194,16 @@
194194
* Adds message to error message stack if not already in the message stack
195195
*
196196
* @param {String} mess
197+
* @para {jQuery} $element
197198
*/
198-
var addErrorMessage = function(mess) {
199+
var addErrorMessage = function(mess, $element) {
199200
if ($.inArray(mess, errorMessages) < 0) {
200201
errorMessages.push(mess);
201202
}
203+
errorInputs.push($element);
204+
$element
205+
.valAttr('current-error', mess)
206+
.removeClass('valid');
202207
};
203208

204209
/** Error messages for this validation */
@@ -244,13 +249,8 @@
244249
);
245250

246251
if(validation !== true) {
247-
errorInputs.push($element);
248-
addErrorMessage(validation);
249-
$element
250-
.valAttr('current-error', validation)
251-
.removeClass('valid');
252-
}
253-
else {
252+
addErrorMessage(validation, $element);
253+
} else {
254254
$element
255255
.valAttr('current-error', false)
256256
.addClass('valid');
@@ -276,6 +276,15 @@
276276
$('.' + $.split(config.errorMessageClass, ' ').join('.')).remove();
277277
$('.jquery_form_error_message').remove();
278278

279+
//
280+
// Run validation callback
281+
//
282+
if( typeof config.onValidate == 'function' ) {
283+
var resp = config.onValidate($form);
284+
if( resp && resp.element && resp.message ) {
285+
addErrorMessage(resp.message, resp.element);
286+
}
287+
}
279288

280289
//
281290
// Validation failed

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
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* @license Dual licensed under the MIT or GPL Version 2 licenses
14-
* @version 1.9.34
14+
* @version 1.9.35
1515
*/
1616
(function($) {
1717

form-validator/security.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/#security-validators
1515
* @license Dual licensed under the MIT or GPL Version 2 licenses
16-
* @version 1.9.34
16+
* @version 1.9.35
1717
*/
1818
(function($) {
1919

form-validator/sweden.dev.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* - validate_swephone
1414
*
1515
* @license Dual licensed under the MIT or GPL Version 2 licenses
16-
* @version 1.9.34
16+
* @version 1.9.35
1717
*/
18-
(function($) {
18+
(function($, window) {
1919

2020
/*
2121
* Validate swedish social security number yyyymmddXXXX
@@ -31,7 +31,7 @@
3131
var month = $.formUtils.parseDateInt(RegExp.$2);
3232
var day = $.formUtils.parseDateInt(RegExp.$3);
3333

34-
// var gender = parseInt( (RegExp.$4) .substring(2,3)) % 2; ==> 1 === male && 0 === female
34+
window.ssnGender = ( parseInt( (RegExp.$4).substring(2,3) ) % 2 ) === 0 ? 'female':'male';
3535

3636
var months = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
3737
if (year % 400 === 0 || year % 4 === 0 && year % 100 !== 0) {
@@ -196,4 +196,4 @@
196196
return $.formUtils.suggest(this, municipalities, settings);
197197
};
198198

199-
})(jQuery);
199+
})(jQuery, window);

form-validator/sweden.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/test.html

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<meta charset="utf-8">
55
<title>QUnit Tests</title>
66
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
7+
<style>
8+
.jquery_form_error_message {
9+
color: darkred;
10+
}
11+
</style>
712
</head>
813
<body>
914
<div id="qunit"></div>
@@ -44,6 +49,11 @@
4449
<br />
4550
<input data-validation="even_number">
4651
</p>
52+
<p>
53+
Callback validation, set this value to &quot;1&quot; and
54+
validation will fail<br />
55+
<input id="callback" />
56+
</p>
4757
<p>
4858
<input type="submit">
4959
</p>
@@ -206,7 +216,7 @@
206216

207217
var links = [
208218
{val:'a', isValid:true},
209-
{val:'asdvs1', isValid:true},
219+
{val:'asdXAvs1', isValid:true},
210220
{val:'a b', isValid:false},
211221
{val:'a-_ bäöåA', isValid:false},
212222
{val:input('a b', {'allowing':' ', '':'alphanumeric'}), isValid:true},
@@ -378,6 +388,15 @@
378388
$('#swedish-county-suggestions').suggestSwedishCounty();
379389
$('#password').displayPasswordStrength();
380390
},
391+
onValidate : function() {
392+
var $callbackInput = $('#callback');
393+
if( $callbackInput.val() == 1 ) {
394+
return {
395+
element : $callbackInput,
396+
message : 'This validation was made in a callback'
397+
};
398+
}
399+
},
381400
onError : function() {
382401
alert('Invalid');
383402
},
@@ -387,7 +406,7 @@
387406
}
388407
});
389408

390-
// Load one module outside $.setupForm() and add file extension even though you do not have to
409+
// Load one module outside $.setupForm() even though you do not have to
391410
$.formUtils.loadModules('date'+dev+'.js', false, false);
392411

393412
// Add a new validator

form-validator/uk.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* - validate_ukvatnumber
1010
*
1111
* @license Dual licensed under the MIT or GPL Version 2 licenses
12-
* @version 1.9.34
12+
* @version 1.9.35
1313
*/
1414
$.formUtils.addValidator({
1515
name : 'validate_ukvatnumber',

0 commit comments

Comments
 (0)