|
27 | 27 | },
|
28 | 28 | isCheckingIfFormValid = false;
|
29 | 29 |
|
30 |
| - $(window).bind('validatorsLoaded formValidationSetup', function(evt, $forms, conf) { |
| 30 | + $.formUtils.$win.bind('validatorsLoaded formValidationSetup', function(evt, $forms, conf) { |
31 | 31 |
|
32 | 32 | var $formsToDisable = conf.disabledFormFilter ? $forms.filter(conf.disabledFormFilter) : $forms,
|
33 |
| - showErrorDialogs = conf.showErrorDialogs === undefined || conf.showErrorDialogs; |
| 33 | + showErrorDialogs = conf.showErrorDialogs === undefined || conf.showErrorDialogs, |
| 34 | + afterValidationCallback = function(evt, result, evtContext) { |
| 35 | + var $this = $(this); |
| 36 | + if (evtContext.indexOf('blur') > -1) { |
| 37 | + $this.unbind('afterValidation', afterValidationCallback); |
| 38 | + } else { |
| 39 | + if (result.isValid) { |
| 40 | + $this.unbind('afterValidation', afterValidationCallback); |
| 41 | + } else if (!$this.valAttr('have-been-blurred')) { |
| 42 | + result.shouldChangeDisplay = false; |
| 43 | + } |
| 44 | + } |
| 45 | + }; |
34 | 46 |
|
35 | 47 | // Toggle form state depending on if it has only valid inputs or not.
|
36 | 48 | $formsToDisable
|
37 | 49 | .addClass(showErrorDialogs ? 'disabled-with-errors' : 'disabled-without-errors')
|
38 | 50 | .find('*[data-validation]')
|
39 |
| - .attr('data-validation-event','keyup change') |
| 51 | + .valAttr('event','keyup change') |
40 | 52 | .on('validation', function(evt, valid) {
|
41 | 53 | if( !isCheckingIfFormValid ) {
|
42 | 54 | isCheckingIfFormValid = true;
|
|
48 | 60 | }
|
49 | 61 | isCheckingIfFormValid = false;
|
50 | 62 | }
|
| 63 | + }) |
| 64 | + .on('afterValidation', afterValidationCallback) |
| 65 | + .on('blur', function() { |
| 66 | + $(this).valAttr('have-been-blurred', 1); |
51 | 67 | });
|
52 | 68 |
|
53 | 69 |
|
|
0 commit comments