Skip to content

Commit 8f6b0c4

Browse files
committed
Finally fixed issue victorjonsson#125
1 parent 152c64d commit 8f6b0c4

11 files changed

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

form-validator/form-test.html

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<form action="" id="form-a" role="form">
7272
<div class="form-group">
7373
<label class="control-label" for="inline-suggestions">Inline suggestions</label>
74-
<input name="inline suggestions" type="text" id="inline-suggestions" class="form-control" data-suggestions="Monkey, Horse, Fox, Tiger, Elephant" />
74+
<input name="inline suggestions" type="text" id="inline-suggestions" class="form-control" data-suggestions="Monkey, Horse, Hound, Fox, Tiger, Elephant" />
7575
</div>
7676

7777
<div class="form-group">
@@ -88,8 +88,8 @@
8888
<label class="control-label">Year</label>
8989
<input name="birth" class="form-control"
9090
data-validation="date"
91-
data-validation-format="yyyy-mm-dd"
92-
data-suggestions="2014-01-15,2014-01-16,2014-01-17" />
91+
data-validation-format="yyyy/mm/dd"
92+
data-suggestions="2014/01/15,2014/01/16,2014/01/17" />
9393
</div>
9494

9595
<div class="form-group">
@@ -209,12 +209,12 @@
209209
<input type="submit" class="button">
210210
<br />
211211
<button class="button" type="button"
212-
onclick="alert('From a is ' + ( $('#form-a').isValid({}, {}, false) ? 'VALID':'NOT VALID'));">
212+
onclick="alert('Form a is ' + ( $('#form-a').isValid({}, {}, false) ? 'VALID':'NOT VALID'));">
213213
Test validation via js (<strong>without error messages</strong>)
214214
</button>
215215
<br />
216216
<button class="button" type="button"
217-
onclick="alert('From a is ' + ( $('#form-a').isValid() ? 'VALID':'NOT VALID'));">
217+
onclick="alert('Form a is ' + ( $('#form-a').isValid() ? 'VALID':'NOT VALID'));">
218218
Test validation via js (showing error messages)
219219
</button>
220220
<br />
@@ -372,9 +372,7 @@ <h2>HTML5 attributes</h2>
372372
}
373373
},
374374
onError : function($form) {
375-
if( !$.formUtils.haltValidation ) {
376-
alert('Invalid '+$form.attr('id'));
377-
}
375+
alert('Invalid '+$form.attr('id'));
378376
},
379377
onSuccess : function($form) {
380378
alert('Valid '+$form.attr('id'));
@@ -394,10 +392,10 @@ <h2>HTML5 attributes</h2>
394392
$.formUtils.loadModules('date'+dev+'.js', false, false);
395393

396394
$('input')
397-
.on('zbeforeValidation', function() {
395+
.on('beforeValidation', function() {
398396
console.log('About to validate input "'+this.name+'"');
399397
})
400-
.on('validationz', function(evt, isValid) {
398+
.on('validation', function(evt, isValid) {
401399
var validationResult = '';
402400
if( isValid === null ) {
403401
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.beta.22
20+
* @version 2.2.beta.25
2121
*/
2222
(function($, window) {
2323

form-validator/jquery.form-validator.js

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

@@ -308,6 +308,14 @@
308308
language = $.extend({}, $.formUtils.LANG, language || {});
309309
displayError = displayError !== false;
310310

311+
if($.formUtils.errorDisplayPreventedWhenHalted) {
312+
// isValid() was called programmatically with argument displayError set
313+
// to false when the validation was halted by any of the validators
314+
delete $.formUtils.errorDisplayPreventedWhenHalted
315+
displayError = false;
316+
}
317+
318+
311319
$.formUtils.isValidatingEntireForm = true;
312320
$.formUtils.haltValidation = false;
313321

@@ -330,8 +338,8 @@
330338
}
331339
},
332340

333-
/** HoldsInputs already validated, to prevent recheck of mulitple checkboxes & radios */
334-
checkedInputs = [],
341+
/** HoldsInputs already validated, to prevent recheck of mulitple checkboxes & radios */
342+
checkedInputs = [],
335343

336344
/** Error messages for this validation */
337345
errorMessages = [],
@@ -371,6 +379,7 @@
371379
if (!ignoreInput(elementName, elementType) && $.inArray(elementName, checkedInputs) < 0 ) {
372380

373381
checkedInputs.push(elementName);
382+
374383
var validation = $.formUtils.validateInput(
375384
$elem,
376385
language,
@@ -379,19 +388,21 @@
379388
'submit'
380389
);
381390

382-
// Run element validation callback
383-
if( typeof conf.onElementValidate == 'function' ) {
384-
conf.onElementValidate((validation === true), $elem, $form, validation);
385-
}
391+
if(validation != null) {
392+
// Run element validation callback
393+
if( typeof conf.onElementValidate == 'function' ) {
394+
conf.onElementValidate((validation === true), $elem, $form, validation);
395+
}
386396

387-
if(validation !== true) {
388-
addErrorMessage(validation, $elem);
389-
} else {
390-
$elem
391-
.valAttr('current-error', false)
392-
.addClass('valid')
393-
.parent()
397+
if(validation !== true) {
398+
addErrorMessage(validation, $elem);
399+
} else {
400+
$elem
401+
.valAttr('current-error', false)
402+
.addClass('valid')
403+
.parent()
394404
.addClass('has-success');
405+
}
395406
}
396407
}
397408
});
@@ -441,6 +452,10 @@
441452
return false;
442453
}
443454

455+
if( !displayError && $.formUtils.haltValidation ) {
456+
$.formUtils.errorDisplayPreventedWhenHalted = true;
457+
}
458+
444459
return !$.formUtils.haltValidation;
445460
};
446461

@@ -565,22 +580,34 @@
565580
$form.bind('submit.validation', function() {
566581
var $form = $(this);
567582

583+
if( $.formUtils.haltValidation ) {
584+
// pressing several times on submit button while validation is halted
585+
return false;
586+
}
587+
568588
if($.formUtils.isLoadingModules) {
569589
setTimeout(function() {
570590
$form.trigger('submit.validation');
571591
}, 200);
572592
return false;
573593
}
594+
574595
var valid = $form.isValid(conf.language, conf);
575-
if( valid && typeof conf.onSuccess == 'function') {
576-
var callbackResponse = conf.onSuccess($form);
577-
if( callbackResponse === false )
578-
return false;
579-
} else if ( !valid && typeof conf.onError == 'function' ) {
580-
conf.onError($form);
596+
597+
if( $.formUtils.haltValidation ) {
598+
// Validation got halted by one of the validators
581599
return false;
582600
} else {
583-
return valid;
601+
if( valid && typeof conf.onSuccess == 'function') {
602+
var callbackResponse = conf.onSuccess($form);
603+
if( callbackResponse === false )
604+
return false;
605+
} else if ( !valid && typeof conf.onError == 'function' ) {
606+
conf.onError($form);
607+
return false;
608+
} else {
609+
return valid;
610+
}
584611
}
585612
})
586613
.bind('reset.validation', function() {

form-validator/jquery.form-validator.min.js

Lines changed: 3 additions & 3 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.beta.22
13+
* @version 2.2.beta.25
1414
*/
1515
(function($) {
1616

form-validator/security.dev.js

Lines changed: 5 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.beta.22
16+
* @version 2.2.beta.25
1717
*/
1818
(function($, window) {
1919

@@ -347,7 +347,7 @@
347347
cache : false,
348348
data : reqParams,
349349
dataType : 'json',
350-
error : function(error) {
350+
error : function(error, err) {
351351
alert('Server validation failed due to: '+error.statusText);
352352
if( window.JSON && window.JSON.stringify ) {
353353
alert(window.JSON.stringify(error));
@@ -417,12 +417,14 @@
417417
return null;
418418

419419
if($.formUtils.isValidatingEntireForm) {
420+
420421
$form
421422
.bind('submit', disableFormSubmit)
422423
.addClass('validating-server-side')
423424
.addClass('on-blur');
424425

425426
$el.addClass('validating-server-side');
427+
$.formUtils.haltValidation = true;
426428

427429
requestServer(serverURL, $el, val, conf, function() {
428430
$form
@@ -436,10 +438,10 @@
436438
$el.valAttr('value-length', val.length);
437439

438440
// fire submission again!
441+
$.formUtils.haltValidation = false;
439442
$form.trigger('submit');
440443
});
441444

442-
$.formUtils.haltValidation = true;
443445
return null;
444446

445447
} else {

0 commit comments

Comments
 (0)