Skip to content

Commit d6e7a01

Browse files
committed
new version coming up
1 parent dc596f3 commit d6e7a01

13 files changed

+114
-56
lines changed

README.md

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

295295
## Changelog
296296

297+
### 2.1.9
298+
* File validation now support multiple files
299+
* Length validation can now be used to validate the number of uploaded files using a file input that supports multiple files
300+
* Validation classes is no longer applied on inputs that for some reason shouldn't become validated
301+
297302
#### 2.1.8
298303
* Now possible to configure the decimal separator when validating float values. Use either the
299304
attribute *data-validation-decimal-separator* or the property *decimalSeparator* when
@@ -337,6 +342,7 @@ calling $.validate()
337342
<a href="http://stevewasiura.waztech.com" target="_blank">Steve Wasiura</a><br />
338343
<a href="https://github.com/robamaton" target="_blank">Joel Sutherland</a><br />
339344
<a href="https://github.com/mattclements" target="_blank">Matt Clements</a><br />
345+
<a href="http://www.joshtoft.com/" target="_blank">Josh Toft</a><br/>
340346
<a href="https://github.com/dfcplc" target="_blank">@dfcplc</a><br />
341347
<a href="https://github.com/coffein" target="_blank">Andree Wendel</a><br />
342348
<a href="http://www.huotmedia.com" target="_blank">Nicholas Huot</a><br />

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.8
13+
* @version 2.1.9
1414
*/
1515
(function($) {
1616

form-validator/file.dev.js

Lines changed: 14 additions & 4 deletions
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.8
13+
* @version 2.1.9
1414
*/
1515
(function($, window) {
1616

@@ -68,9 +68,19 @@
6868
*/
6969
$.formUtils.addValidator({
7070
name : 'extension',
71-
validatorFunction : function(val, $input) {
72-
var ext = val.substr( val.lastIndexOf('.')+1 );
73-
return $.inArray(ext.toLowerCase(), _getTypes($input)) > -1;
71+
validatorFunction : function(value, $input) {
72+
var valid = true,
73+
types = _getTypes($input);
74+
75+
$.each($input.get(0).files || [], function(i, file) {
76+
var val = file.value,
77+
ext = val.substr( val.lastIndexOf('.')+1 );
78+
if( $.inArray(ext.toLowerCase(), types) == -1 ) {
79+
valid = false;
80+
return false;
81+
}
82+
});
83+
return valid;
7484
},
7585
errorMessage : 'The file you are trying to upload is of wrong type',
7686
errorMessageKey: 'wrongFileType'

form-validator/file.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/form-test.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,28 @@
8585
</div>
8686

8787
<div class="form-group">
88-
<label class="control-label">Optional Server validation</label>
88+
<label class="control-label">Server validation</label>
8989
<input class="form-control" name="code"
9090
data-validation-help="The word is &quot;secret&quot;"
91-
data-validation-optional="true"
9291
data-validation="server"
9392
data-validation-url="http://formvalidator.net/validate-email.php" />
9493
</div>
9594

9695
<div class="form-group">
9796
<label class="control-label">File validation</label>
9897
<input type="file" name="some-file" class="form-control"
99-
data-validation="size mime"
98+
data-validation="size mime required"
99+
data-validation-error-msg="You must upload an image file"
100+
data-validation-allowing="jpg, png, ico"
101+
data-validation-max-size="100kb" />
102+
</div>
103+
104+
<div class="form-group">
105+
<label class="control-label">File validation (multiple)</label>
106+
<input type="file" multiple="multiple" name="some-file" class="form-control"
107+
data-validation="size mime required length"
108+
data-validation-length="min2"
109+
data-validation-error-msg="You must upload at least two image files"
100110
data-validation-allowing="jpg, png, ico"
101111
data-validation-max-size="100kb" />
102112
</div>

form-validator/jquery.form-validator.js

Lines changed: 48 additions & 37 deletions
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.8
8+
* @version 2.1.9
99
*/
1010
(function($) {
1111

@@ -109,7 +109,7 @@
109109
.removeClass(config.errorElementClass)
110110
.css('border-color', '')
111111
.parent()
112-
.find('.'+config.errorMessageClass).remove();
112+
.find('.'+config.errorMessageClass).remove();
113113

114114
// Twitter bs
115115
$form.find('.has-error').removeClass('has-error');
@@ -204,15 +204,18 @@
204204
* @para {jQuery} $element
205205
*/
206206
var addErrorMessage = function(mess, $element) {
207-
if ($.inArray(mess, errorMessages) < 0) {
208-
errorMessages.push(mess);
209-
}
210-
errorInputs.push($element);
211-
$element
212-
.valAttr('current-error', mess)
213-
.removeClass('valid')
214-
.parent()
207+
// validate server side will return null as error message before the server is requested
208+
if(mess !== null) {
209+
if ($.inArray(mess, errorMessages) < 0) {
210+
errorMessages.push(mess);
211+
}
212+
errorInputs.push($element);
213+
$element
214+
.valAttr('current-error', mess)
215+
.removeClass('valid')
216+
.parent()
215217
.removeClass('has-success');
218+
}
216219
},
217220

218221
/** Error messages for this validation */
@@ -495,6 +498,7 @@
495498
errorMessagePosition : 'element', // Can be either "top" or "element"
496499
scrollToTopOnError : true,
497500
dateFormat : 'yyyy-mm-dd',
501+
addValidClassOnAll : false, // whether or not to apply class="valid" even if the input wasn't validated
498502
decimalSeparator : '.'
499503
}
500504
},
@@ -704,14 +708,18 @@
704708
// if empty AND optional attribute is present
705709
// OR depending on a checkbox being checked AND checkbox is checked, return true
706710
if ((!value && optional === 'true') || (validationDependsOnCheckedInput && !validationDependentInputIsChecked)) {
707-
return null;
711+
return config.addValidClassOnAll ? true:null;
708712
}
709713

710714
var validationRules = $element.attr(config.validationRuleAttribute),
711715

712716
// see if form element has inline err msg attribute
713717
validationErrorMsg = true;
714718

719+
if( !validationRules ) {
720+
return config.addValidClassOnAll ? true:null;
721+
}
722+
715723
$.split(validationRules, function(rule) {
716724
if( rule.indexOf('validate_') !== 0 ) {
717725
rule = 'validate_' + rule;
@@ -1098,7 +1106,7 @@
10981106
badSecurityAnswer : 'You have not given a correct answer to the security question',
10991107
badDate : 'You have not given a correct date',
11001108
lengthBadStart : 'You must give an answer between ',
1101-
lengthBadEnd : 'characters',
1109+
lengthBadEnd : ' characters',
11021110
lengthTooLongStart : 'You have given an answer longer than ',
11031111
lengthTooShortStart : 'You have given an answer shorter than ',
11041112
notConfirmed : 'Values could not be confirmed',
@@ -1255,38 +1263,41 @@
12551263
*/
12561264
$.formUtils.addValidator({
12571265
name : 'length',
1258-
validatorFunction : function(value, $el, config, lang) {
1259-
var lengthAllowed = $el.valAttr('length');
1266+
validatorFunction : function(val, $el, config, lang) {
1267+
var lengthAllowed = $el.valAttr('length'),
1268+
type = $el.attr('type');
1269+
12601270
if(lengthAllowed == undefined) {
12611271
var elementType = $el.get(0).nodeName;
12621272
alert('Please add attribute "data-validation-length" to '+elementType+' named '+$el.attr('name'));
12631273
return true;
12641274
}
12651275

1266-
// check if length is above min, below max, within range etc.
1267-
var lengthCheckResults = $.formUtils.numericRangeCheck(value.length, lengthAllowed),
1268-
checkResult;
1276+
// check if length is above min, below max or within range.
1277+
var len = type == 'file' && $el.get(0).files !== undefined ? $el.get(0).files.length : val.length,
1278+
lengthCheckResults = $.formUtils.numericRangeCheck(len, lengthAllowed),
1279+
checkResult;
12691280

1270-
switch(lengthCheckResults[0] )
1271-
{ // outside of allowed range
1272-
case "out":
1273-
this.errorMessage = lang.lengthBadStart + lengthAllowed + lang.lengthBadEnd;
1274-
checkResult = false;
1275-
break;
1276-
// too short
1277-
case "min":
1278-
this.errorMessage = lang.lengthTooShortStart + lengthCheckResults[1] + lang.lengthBadEnd;
1279-
checkResult = false;
1280-
break;
1281-
// too long
1282-
case "max":
1283-
this.errorMessage = lang.lengthTooLongStart + lengthCheckResults[1] + lang.lengthBadEnd;
1284-
checkResult = false;
1285-
break;
1286-
// ok
1287-
default:
1288-
checkResult = true;
1289-
}
1281+
switch(lengthCheckResults[0] )
1282+
{ // outside of allowed range
1283+
case "out":
1284+
this.errorMessage = lang.lengthBadStart + lengthAllowed + lang.lengthBadEnd;
1285+
checkResult = false;
1286+
break;
1287+
// too short
1288+
case "min":
1289+
this.errorMessage = lang.lengthTooShortStart + lengthCheckResults[1] + lang.lengthBadEnd;
1290+
checkResult = false;
1291+
break;
1292+
// too long
1293+
case "max":
1294+
this.errorMessage = lang.lengthTooLongStart + lengthCheckResults[1] + lang.lengthBadEnd;
1295+
checkResult = false;
1296+
break;
1297+
// ok
1298+
default:
1299+
checkResult = true;
1300+
}
12901301

12911302
return checkResult;
12921303
},

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.8
13+
* @version 2.1.9
1414
*/
1515
(function($) {
1616

form-validator/qunit.html

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,19 @@
5757
message = 'Check that input[value='+obj.val.attr('value')+'] is '+(obj.isValid ? 'valid':'invalid');
5858
}
5959

60-
equal(
60+
if( $el.attr('data-validation-optional') && !$el.val() ) {
61+
equal(
62+
result,
63+
null,
64+
message
65+
);
66+
} else {
67+
equal(
6168
typeof(result),
6269
obj.isValid ? 'boolean':'string', // returns true if valid, error message otherwise
6370
message
64-
);
71+
);
72+
}
6573
}
6674

6775
function runAllTests() {
@@ -395,10 +403,12 @@
395403
equal(10485760, $.formUtils.convertSizeNameToBytes('10mb'));
396404
equal(10485760, $.formUtils.convertSizeNameToBytes('10m'));
397405

406+
/*
407+
todo: test this somehow
398408
var extensionTests = [
399409
{val:input('file.jpg', {'allowing' : 'jpg', '':'extension'}), isValid:true},
400410
{val:input('file.JPG', {'allowing' : 'jpg', '':'extension'}), isValid:true},
401-
{val:input('file.jpgs', {'allowing' : 'jpg', '':'extension'}), isValid:false},
411+
{val:input('file.jpgs', {'allowing' : 'jpg', '':'extension'}, {type:'file'}), isValid:false},
402412
{val:input('file', {'allowing' : 'jpg', '':'extension'}), isValid:false},
403413
{val:input('file.jpeg', {'allowing' : 'jpg', '':'extension'}), isValid:true},
404414
{val:input('file.JPEG', {'allowing' : 'jpg, png, gif', '':'extension'}), isValid:true},
@@ -409,6 +419,7 @@
409419
$.each(extensionTests, function(i, obj) {
410420
runTest(obj, 'extension');
411421
});
422+
*/
412423
});
413424

414425
test('Confirmation', function() {

form-validator/security.dev.js

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

@@ -276,6 +276,15 @@
276276

277277
/*
278278
* Server validation
279+
* Flow (form submission):
280+
* 1) Check if the value already has been validated on the server . If so, display the validation
281+
* result and continue the validation process, otherwise continue to step 2
282+
* 2) Return false as if the value is invalid and set $.formUtils.haltValidation to true
283+
* 3) Disable form submission on the form being validated
284+
* 4) Request the server with value and input name and add class 'validating-server-side' to the form
285+
* 5) When the server responds an attribute will be added to the element
286+
* telling the validator that the input has a valid/invalid value and enable form submission
287+
* 6) Run form submission again (back to step 1)
279288
*/
280289
$.formUtils.addValidator({
281290
name : 'server',
@@ -318,6 +327,7 @@
318327
return false;
319328

320329
} else {
330+
// validaiton on blur
321331
$form.addClass('validating-server-side');
322332
requestServer(serverURL, $el, val, conf, function() {
323333
$form.removeClass('validating-server-side');

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.8
16+
* @version 2.1.9
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.8
12+
* @version 2.1.9
1313
*/
1414
$.formUtils.addValidator({
1515
name : 'ukvatnumber',

formvalidator.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"validation",
88
"validator"
99
],
10-
"version" : "2.1.8",
10+
"version" : "2.1.9",
1111
"author" : {
1212
"name": "Victor Jonsson",
1313
"url": "http://victorjonsson.se",

0 commit comments

Comments
 (0)