Skip to content

Commit 4d0c0b0

Browse files
committed
IMPROVE When an input is empty and validation is not required, it doesn't run the others validations and clean the classes.
1 parent 857d0bf commit 4d0c0b0

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

form-validator/jquery.form-validator.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
// Remove possible error style applied by previous validation
105105
$element
106106
.removeClass(config.errorElementClass)
107-
.css('border-color', '')
108107
.parent()
109108
.find('.'+config.errorMessageClass).remove();
110109

@@ -119,6 +118,8 @@
119118

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

121+
console.log(validation);
122+
122123
if(validation === true) {
123124
$element
124125
.addClass('valid')
@@ -129,7 +130,7 @@
129130
.removeClass('valid')
130131
.parent()
131132
.removeClass('has-error')
132-
.removeClass('has-success');
133+
.removeClass('has-success');
133134
} else {
134135
$element
135136
.addClass(config.errorElementClass)
@@ -147,10 +148,6 @@
147148
$parent.addClass('has-error'); // twitter bs
148149
}
149150

150-
if(config.borderColorOnError !== '') {
151-
$element.css('border-color', config.borderColorOnError);
152-
}
153-
154151
if(attachKeyupEvent) {
155152
$element.bind('keyup', function() {
156153
$(this).validateInputOnBlur(language, config, false, 'keyup');
@@ -272,8 +269,7 @@
272269
// Reset style and remove error class
273270
//
274271
$form.find('.has-error').removeClass('has-error');
275-
$form.find('input,textarea,select')
276-
.css('border-color', '')
272+
$form.find('input,textarea,select')
277273
.removeClass(config.errorElementClass);
278274

279275
//
@@ -301,10 +297,7 @@
301297
$.formUtils.isValidatingEntireForm = false;
302298

303299
// Apply error style to invalid inputs
304-
$.each(errorInputs, function(i, $input) {
305-
if (config.borderColorOnError !== '') {
306-
$input.css('border-color', config.borderColorOnError);
307-
}
300+
$.each(errorInputs, function(i, $input) {
308301
$input
309302
.addClass(config.errorElementClass)
310303
.parent()
@@ -722,6 +715,10 @@
722715
return config.addValidClassOnAll ? true:null;
723716
}
724717

718+
if( value.trim() === '' && validationRules.indexOf('required') === -1 ) {
719+
return null;
720+
}
721+
725722
$.split(validationRules, function(rule) {
726723
if( rule.indexOf('validate_') !== 0 ) {
727724
rule = 'validate_' + rule;
@@ -803,8 +800,8 @@
803800
year = findDateUnit('y', formatParts, matches);
804801

805802
if ((month === 2 && day > 28 && (year % 4 !== 0 || year % 100 === 0 && year % 400 !== 0))
806-
|| (month === 2 && day > 29 && (year % 4 === 0 || year % 100 !== 0 && year % 400 === 0))
807-
|| month > 12 || month === 0) {
803+
|| (month === 2 && day > 29 && (year % 4 === 0 || year % 100 !== 0 && year % 400 === 0))
804+
|| month > 12 || month === 0) {
808805
return false;
809806
}
810807
if ((this.isShortMonth(month) && day > 30) || (!this.isShortMonth(month) && day > 31) || day === 0) {
@@ -1374,7 +1371,7 @@
13741371
additionalChars = $el.attr('data-validation-allowing'),
13751372
pattern = '';
13761373

1377-
if( additionalChars ) {
1374+
if( additionalChars) {
13781375
pattern = patternStart + additionalChars + patternEnd;
13791376
var extra = additionalChars.replace(/\\/g, '');
13801377
if( extra.indexOf(' ') > -1 ) {
@@ -1386,8 +1383,9 @@
13861383
pattern = patternStart + patternEnd;
13871384
this.errorMessage = language.badAlphaNumeric;
13881385
}
1389-
1386+
13901387
return new RegExp(pattern).test(val);
1388+
13911389
},
13921390
errorMessage : '',
13931391
errorMessageKey: ''

0 commit comments

Comments
 (0)