|
58 | 58 | if( !isCheckingIfFormValid ) {
|
59 | 59 | isCheckingIfFormValid = true;
|
60 | 60 | var $form = $(this).closest('form');
|
61 |
| - if( valid && $form.isValid(conf.language, conf, false) ) { |
| 61 | + if(valid && peekIfFormIsSuccessfullyValidated($form, this, conf)) { |
62 | 62 | toggleFormState($form, 'enabled');
|
63 | 63 | } else {
|
64 | 64 | toggleFormState($form, 'disabled');
|
|
83 | 83 | });
|
84 | 84 |
|
85 | 85 | // Notice! Async validator can't be validated onkeyup
|
86 |
| - // We can not determine if an input has an async validator by looking at the markup. |
87 |
| - // The solution here would be to add the flag `async` to addValidator configuration |
88 |
| - // for now we will have to hard code known async validators |
89 |
| - $formsToDisable.find('[data-validation~="server"],[data-validation~="dimension"]') |
90 |
| - .valAttr('event', 'change'); |
| 86 | + $formsToDisable.find('[data-validation-async]').valAttr('event', 'change'); |
91 | 87 |
|
92 | 88 | // Make all inputs validated on keyup, require validateOnEvent in validation config
|
93 | 89 | toggleFormState($formsToDisable, 'disabled');
|
|
101 | 97 | }
|
102 | 98 | });
|
103 | 99 |
|
| 100 | + // We want to peek at the form to check if all is valid, we don't want to trigger |
| 101 | + // the validators since that seems to cause unwanted side effects, that's hard to foresee |
| 102 | + function peekIfFormIsSuccessfullyValidated($form, excludeInputElement, config) { |
| 103 | + var allValid = true; |
| 104 | + $form.find('[data-validation]').each(function() { |
| 105 | + if (this !== excludeInputElement) { |
| 106 | + var $elem = $(this); |
| 107 | + if (!$elem.hasClass(config.successElementClass) || $elem.hasClass(config.errorElementClass)) { |
| 108 | + allValid = false; |
| 109 | + return false; |
| 110 | + } |
| 111 | + } |
| 112 | + }); |
| 113 | + return allValid; |
| 114 | + } |
| 115 | + |
104 | 116 | })(jQuery, window);
|
0 commit comments