Skip to content

Commit 40fd9fb

Browse files
committed
victorjonsson#599 quick-fix for async validators when used together with toggleDisabled
1 parent 8f37308 commit 40fd9fb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/modules/security.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,21 @@
348348

349349
var requestServer = function (serverURL, $element, val, conf, callback) {
350350
var reqParams = $element.valAttr('req-params') || $element.data('validation-req-params') || {},
351+
inputName = $element.valAttr('param-name') || $element.attr('name'),
351352
handleResponse = function (response, callback) {
352353
callback(response);
353354
};
354355

356+
if (!inputName) {
357+
throw new Error('Missing input name used for http requests made by server validator');
358+
}
355359
if (!reqParams) {
356360
reqParams = {};
357361
}
358362
if (typeof reqParams === 'string') {
359363
reqParams = $.parseJSON(reqParams);
360364
}
361-
reqParams[$element.valAttr('param-name') || $element.attr('name')] = val;
365+
reqParams[inputName] = val;
362366

363367
$.ajax({
364368
url: serverURL,
@@ -583,7 +587,7 @@
583587
callback: function (result) {
584588
$form.find('[data-validation~="recaptcha"]')
585589
.trigger('validation', (result && result !== ''));
586-
590+
587591
},
588592
'expired-callback': function() {
589593
$form.find('[data-validation~="recaptcha"]').trigger('validation', false);

src/modules/toggleDisabled.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
}
8383
});
8484

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');
8591

8692
// Make all inputs validated on keyup, require validateOnEvent in validation config
8793
toggleFormState($formsToDisable, 'disabled');

0 commit comments

Comments
 (0)