Skip to content

Commit b064add

Browse files
committed
added unit tests, and minor bug fixes
1 parent 689268f commit b064add

File tree

9 files changed

+113
-22
lines changed

9 files changed

+113
-22
lines changed

form-validator/date.dev.js

Lines changed: 2 additions & 2 deletions
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.33
15+
* @version 1.9.34
1616
*/
1717
(function($) {
1818

@@ -27,7 +27,7 @@
2727
} else {
2828
var hours = parseInt(time.split(':')[0],10);
2929
var minutes = parseInt(time.split(':')[1],10);
30-
if((hours > 24 || minutes > 59) || (hours === 24 && minutes > 0)) {
30+
if( hours > 23 || minutes > 59 ) {
3131
return false;
3232
}
3333
}

form-validator/date.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/jquery.form-validator.js

Lines changed: 20 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.33
8+
* @version 1.9.34
99
*/
1010
(function($) {
1111

@@ -343,7 +343,7 @@
343343
sugs = $.split($field.attr('data-suggestions'));
344344

345345
if( sugs.length > 0 ) {
346-
new $.formUtils.suggest($field, sugs, settings);
346+
$.formUtils.suggest($field, sugs, settings);
347347
}
348348
});
349349
return this;
@@ -436,9 +436,7 @@
436436
if( config.modules != '' ) {
437437
if( typeof config.onModulesLoaded == 'function' ) {
438438
$.formUtils.on('load', function() {
439-
$.split(config.form, function(formQuery) {
440-
config.onModulesLoaded( $(formQuery) );
441-
});
439+
config.onModulesLoaded();
442440
});
443441
}
444442
$.formUtils.loadModules(config.modules);
@@ -546,10 +544,21 @@
546544
* The script will be cached by the browser unless the module
547545
* name ends with .dev
548546
*
549-
* @param {String} modules - Comma separated string
550-
* @param {String} path - Optional
547+
* @param {String} modules - Comma separated string with module file names (no directory nor file extension)
548+
* @param {String} [path] - Optional, path where the module files is located if their not in the same directory as the core modules
549+
* @param {Boolean} [fireEvent] - Optional, whether or not to fire event 'load' when modules finished loading
551550
*/
552-
loadModules : function(modules, path) {
551+
loadModules : function(modules, path, fireEvent) {
552+
553+
if( fireEvent === undefined )
554+
fireEvent = true;
555+
556+
if( $.formUtils.isLoadingModules ) {
557+
setTimeout(function() {
558+
$.formUtils.loadModules(modules, path, fireEvent);
559+
});
560+
return;
561+
}
553562

554563
var loadModuleScripts = function(modules, path) {
555564
var moduleList = $.split(modules),
@@ -558,7 +567,9 @@
558567
numModules--;
559568
if( numModules == 0 ) {
560569
$.formUtils.isLoadingModules = false;
561-
$.formUtils.trigger('load', path);
570+
if( fireEvent ) {
571+
$.formUtils.trigger('load', path);
572+
}
562573
}
563574
};
564575

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.33
14+
* @version 1.9.34
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.33
16+
* @version 1.9.34
1717
*/
1818
(function($) {
1919

form-validator/sweden.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* - validate_swephone
1414
*
1515
* @license Dual licensed under the MIT or GPL Version 2 licenses
16-
* @version 1.9.33
16+
* @version 1.9.34
1717
*/
1818
(function($) {
1919

form-validator/test.html

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
<br />
4040
<input type="checkbox" data-validation="required" />
4141
</p>
42+
<p>
43+
<strong>Even numbers only</strong>
44+
<br />
45+
<input data-validation="even_number">
46+
</p>
4247
<p>
4348
<input type="submit">
4449
</p>
@@ -241,7 +246,7 @@
241246
});
242247

243248
/*
244-
* LENGTH VALIDATION
249+
* DATE VALIDATION
245250
*/
246251
test("Date validation", function() {
247252

@@ -261,7 +266,9 @@
261266
{val:input('29/02/2000', {'format':'dd/mm/yyyy', '':'date'}), isValid:true},
262267
{val:input('29/02/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
263268
{val:input('29/13/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
264-
{val:input('29/00/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false}
269+
{val:input('29/00/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
270+
{val:'2014-01-01', isValid:true},
271+
{val:'1880-01-01', isValid:true}
265272
];
266273

267274
$.each(dates, function(i, obj) {
@@ -270,7 +277,66 @@
270277
});
271278

272279
/*
273-
* DATE VALIDATION
280+
* BIRTH DATE VALIDATION
281+
*/
282+
test("Birth date validation", function() {
283+
284+
clearForm();
285+
286+
var dates = [
287+
{val:'2000-01-01', isValid:true},
288+
{val:'2000-01-1', isValid:false},
289+
{val:'2000-01-32', isValid:false},
290+
{val:'2000-02-29', isValid:true}, // leap year
291+
{val:'2013-02-29', isValid:false},
292+
{val:'2000-04-31', isValid:false},
293+
{val:'2000-13-1', isValid:false},
294+
{val:'2000-1-1', isValid:false},
295+
{val:'-01-01', isValid:false},
296+
{val:input('01/01/2000', {'format':'dd/mm/yyyy', '':'date'}), isValid:true},
297+
{val:input('29/02/2000', {'format':'dd/mm/yyyy', '':'date'}), isValid:true},
298+
{val:input('29/02/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
299+
{val:input('29/13/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
300+
{val:input('29/00/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
301+
{val:'2014-01-01', isValid:false}, // no future date
302+
{val:'1880-01-01', isValid:false} // no date that is to old
303+
];
304+
305+
$.each(dates, function(i, obj) {
306+
runTest(obj, 'birthdate');
307+
});
308+
});
309+
310+
/*
311+
* TIME VALIDATION
312+
*/
313+
test("Time validation", function() {
314+
315+
clearForm();
316+
317+
var links = [
318+
{val:'00:00', isValid:true},
319+
{val:'00:01', isValid:true},
320+
{val:'09:59', isValid:true},
321+
{val:'19:59', isValid:true},
322+
{val:'19:60', isValid:false},
323+
{val:'19:61', isValid:false},
324+
{val:'24:01', isValid:false},
325+
{val:'24:00', isValid:false},
326+
{val:'2200', isValid:false},
327+
{val:'', isValid:false},
328+
{val:'23', isValid:false},
329+
{val:'23;00', isValid:false},
330+
{val:'23-00', isValid:false}
331+
];
332+
333+
$.each(links, function(i, obj) {
334+
runTest(obj, 'time');
335+
});
336+
});
337+
338+
/*
339+
* LENGTH VALIDATION
274340
*/
275341
test("Length validation", function() {
276342

@@ -304,8 +370,9 @@
304370
language : {
305371
requiredFields: 'Du måste bocka för denna'
306372
},
307-
modules : 'date'+dev+', location'+dev+', security'+dev+', sweden'+dev+', uk'+dev,
373+
modules : 'security'+dev+', location'+dev+', sweden'+dev+', uk'+dev,
308374
onModulesLoaded: function( $form ) {
375+
console.log('About to run all tests');
309376
runAllTests();
310377
$('#country-suggestions').suggestCountry();
311378
$('#swedish-county-suggestions').suggestSwedishCounty();
@@ -320,6 +387,19 @@
320387
}
321388
});
322389

390+
// Load one module outside $.setupForm() and add file extension even though you do not have to
391+
$.formUtils.loadModules('date'+dev+'.js', false, false);
392+
393+
// Add a new validator
394+
$.formUtils.addValidator({
395+
name : 'even_number',
396+
validate : function(value, $el, config, language, $form) {
397+
return parseInt(value, 10) % 2 === 0;
398+
},
399+
errorMessage : 'You have to give an even number',
400+
errorMessageKey: 'badEvenNumber'
401+
});
402+
323403
})(jQuery);
324404
</script>
325405
<body>

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.33
12+
* @version 1.9.34
1313
*/
1414
$.formUtils.addValidator({
1515
name : 'validate_ukvatnumber',

0 commit comments

Comments
 (0)