Skip to content

Commit 37396d0

Browse files
committed
Fix for issue victorjonsson#152
1 parent a16d4f1 commit 37396d0

11 files changed

+55
-48
lines changed

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.2.0
13+
* @version 2.2.beta.11
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.2.0
13+
* @version 2.2.beta.11
1414
*/
1515
(function($, window) {
1616

form-validator/form-test.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
<label class="control-label">Server validation</label>
166166
<input class="form-control" name="code" value="secret"
167167
data-validation-help="The word is &quot;secret&quot;"
168-
data-validation="alphanumeric server"
168+
data-validation="server"
169169
data-validation-url="http://formvalidator.net/validate-email.php" />
170170
</div>
171171
<div class="form-group">
@@ -394,10 +394,10 @@ <h2>HTML5 attributes</h2>
394394
$.formUtils.loadModules('date'+dev+'.js', false, false);
395395

396396
$('input')
397-
.on('beforeValidation', function() {
397+
.on('zbeforeValidation', function() {
398398
console.log('About to validate input "'+this.name+'"');
399399
})
400-
.on('validation', function(evt, isValid) {
400+
.on('validationz', function(evt, isValid) {
401401
var validationResult = '';
402402
if( isValid === null ) {
403403
validationResult = 'not validated';

form-validator/html5.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @website http://formvalidator.net/
1919
* @license Dual licensed under the MIT or GPL Version 2 licenses
20-
* @version 2.2.0
20+
* @version 2.2.beta.11
2121
*/
2222
(function($, window) {
2323

form-validator/jquery.form-validator.js

Lines changed: 33 additions & 33 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.2.0
8+
* @version 2.2.beta.11
99
*/
1010
(function($) {
1111

@@ -97,7 +97,7 @@
9797
$.fn.validateOnBlur = function(language, settings) {
9898
this.find('input[data-validation],textarea[data-validation],select[data-validation]')
9999
.bind('blur.validation', function() {
100-
$(this).validateInputOnBlur(language, settings);
100+
$(this).validateInputOnBlur(language, settings, true, 'blur');
101101
});
102102

103103
return this;
@@ -116,7 +116,7 @@
116116
etype = $el.attr("data-validation-event");
117117
if (etype){
118118
$el.bind(etype + ".validation", function(){
119-
$(this).validateInputOnBlur(language, settings, false, etype);
119+
$(this).validateInputOnBlur(language, settings, true, etype);
120120
});
121121
}
122122
});
@@ -139,8 +139,6 @@
139139
// Remove previously added event listeners
140140
this.find('.has-help-txt')
141141
.valAttr('has-keyup-event', false)
142-
.valAttr('backend-valid', false)
143-
.valAttr('backend-invalid', false)
144142
.removeClass('has-help-txt');
145143

146144
// Add help text listeners
@@ -188,23 +186,21 @@
188186
*
189187
* @param {Object} [language] Optional, will override $.formUtils.LANG
190188
* @param {Object} [conf] Optional, will override the default settings
191-
* @param {Boolean} [attachKeyupEvent] Optional
192-
* @param {String} [eventContext]
189+
* @param {Boolean} attachKeyupEvent Optional
190+
* @param {String} eventType
193191
* @return {jQuery}
194192
*/
195-
$.fn.validateInputOnBlur = function(language, conf, attachKeyupEvent, eventContext) {
196-
if(attachKeyupEvent === undefined)
197-
attachKeyupEvent = true;
198-
if(!eventContext)
199-
eventContext = 'blur';
193+
$.fn.validateInputOnBlur = function(language, conf, attachKeyupEvent, eventType) {
194+
console.log(eventType);
195+
$.formUtils.eventType = eventType;
200196

201197
if( (this.valAttr('suggestion-nr') || this.valAttr('postpone') || this.hasClass('hasDatepicker')) && !window.postponedValidation ) {
202-
// This validation has to be postponed
198+
// This validation has to be postponed
203199
var _self = this,
204200
postponeTime = this.valAttr('postpone') || 200;
205201

206202
window.postponedValidation = function() {
207-
_self.validateInputOnBlur(language, conf, attachKeyupEvent);
203+
_self.validateInputOnBlur(language, conf, attachKeyupEvent, eventType);
208204
window.postponedValidation = false;
209205
};
210206
setTimeout(function() {
@@ -218,7 +214,6 @@
218214

219215
language = $.extend({}, $.formUtils.LANG, language || {});
220216
_removeErrorStyle(this, conf);
221-
222217
var $elem = this,
223218
$form = $elem.closest("form"),
224219
validationRule = $elem.attr(conf.validationRuleAttribute),
@@ -227,11 +222,9 @@
227222
language,
228223
$.extend({}, conf, {errorMessagePosition:'element'}),
229224
$form,
230-
eventContext
225+
eventType
231226
);
232-
233-
$elem.trigger('validation', [validation===null ? null : validation===true]);
234-
227+
235228
if(validation === true) {
236229
$elem
237230
.addClass('valid')
@@ -243,9 +236,11 @@
243236
_setInlineErrorMessage($elem, validation, conf, conf.errorMessagePosition);
244237

245238
if(attachKeyupEvent) {
246-
$elem.bind('keyup', function() {
247-
$(this).validateInputOnBlur(language, conf, false, 'keyup');
248-
});
239+
$elem
240+
.unbind('keyup.validation')
241+
.bind('keyup.validation', function() {
242+
$(this).validateInputOnBlur(language, conf, false, 'keyup');
243+
});
249244
}
250245
}
251246

@@ -358,8 +353,6 @@
358353
'submit'
359354
);
360355

361-
$elem.trigger('validation', [validation===true]);
362-
363356
// Run element validation callback
364357
if( typeof conf.onElementValidate == 'function' ) {
365358
conf.onElementValidate((validation === true), $elem, $form, validation);
@@ -790,8 +783,8 @@
790783

791784
/**
792785
* Validate the value of given element according to the validation rules
793-
* found in the attribute data-validation. Will return true if valid,
794-
* error message otherwise
786+
* found in the attribute data-validation. Will return null if no validation
787+
* should take place, returns true if valid or error message if not valid
795788
*
796789
* @param {jQuery} $elem
797790
* @param {Object} language ($.formUtils.LANG)
@@ -865,19 +858,22 @@
865858
$elem = $("[name='"+$elem.attr('name')+"']:eq(0)");
866859
}
867860

868-
var isValid = true;
861+
var isValid = null;
869862
if( eventContext != 'keyup' || validator.validateOnKeyUp ) {
870863
isValid = validator.validatorFunction(value, $elem, conf, language, $form);
871864
}
872865

873866
if(!isValid) {
874-
validationErrorMsg = $elem.attr(conf.validationErrorMsgAttribute+'-'+rule.replace('validate_', ''));
875-
if( !validationErrorMsg ) {
876-
validationErrorMsg = $elem.attr(conf.validationErrorMsgAttribute);
867+
validationErrorMsg = null;
868+
if( isValid !== null ) {
869+
validationErrorMsg = $elem.attr(conf.validationErrorMsgAttribute+'-'+rule.replace('validate_', ''));
877870
if( !validationErrorMsg ) {
878-
validationErrorMsg = language[validator.errorMessageKey];
879-
if( !validationErrorMsg )
880-
validationErrorMsg = validator.errorMessage;
871+
validationErrorMsg = $elem.attr(conf.validationErrorMsgAttribute);
872+
if( !validationErrorMsg ) {
873+
validationErrorMsg = language[validator.errorMessageKey];
874+
if( !validationErrorMsg )
875+
validationErrorMsg = validator.errorMessage;
876+
}
881877
}
882878
}
883879
return false; // breaks the iteration
@@ -890,8 +886,12 @@
890886
}, ' ');
891887

892888
if( typeof validationErrorMsg == 'string' ) {
889+
$elem.trigger('validation', false);
893890
return validationErrorMsg;
891+
} else if( validationErrorMsg === null && !conf.addValidClassOnAll ) {
892+
return null;
894893
} else {
894+
$elem.trigger('validation', true);
895895
return true;
896896
}
897897
},

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.2.0
13+
* @version 2.2.beta.11
1414
*/
1515
(function($) {
1616

form-validator/security.dev.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* - cvv
1414
*
1515
* @website http://formvalidator.net/#security-validators
16-
* @version 2.2.0
16+
* @version 2.2.beta.11
1717
*/
1818
(function($, window) {
1919

@@ -388,10 +388,15 @@
388388
serverURL = conf.backendUrl;
389389
}
390390

391+
console.log('IN HERE:');
392+
console.log($.formUtils.eventType);
393+
391394
if(backendValid)
392395
return true;
393396
else if(backendInvalid)
394397
return false;
398+
else if($.formUtils.eventType == 'keyup')
399+
return null;
395400

396401
if($.formUtils.isValidatingEntireForm) {
397402
$form
@@ -410,12 +415,14 @@
410415
$form.unbind('submit', disableFormSubmit);
411416
$el.removeClass('validating-server-side');
412417

418+
$el.valAttr('value-length', val.length);
419+
413420
// fire submission again!
414421
$form.trigger('submit');
415422
});
416423

417424
$.formUtils.haltValidation = true;
418-
return false;
425+
return null;
419426

420427
} else {
421428
// validaiton on blur
@@ -426,7 +433,7 @@
426433
$el.removeClass('validating-server-side');
427434
$el.trigger('blur');
428435
});
429-
return true;
436+
return null;
430437
}
431438
},
432439
errorMessage : '',

0 commit comments

Comments
 (0)