-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refs #69450 - wait for all validation checks to complete before submitting form #335
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except................where's that CHANGELOG?
_this.validation_test_count = 0; | ||
|
||
// Scope the data-validation only to the form submitted | ||
$('[data-validate]', $(this)).each(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$(this)
here is actually $this
}); | ||
|
||
// Catch visible errors for image/file inputs hitting the fae config file size limiter | ||
$('.input.file', $(this)).each(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This $(this)
is also $this
} else { | ||
// check again if it hasn't run more than 50 times | ||
// (to prevent against infinite loop) | ||
if (_this.validation_test_count < 50) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels uncomfortably hacky. I'm assuming the 50
was arbitrarily selected, but setting a timeout of 2500
would also be an arbitrary number. However, since it is based on AJAX that may or may not send, it's the best solution.
Ultimately, the ideal solution would be to receive a Promise (or equivalent, you're more familiar with Judge's internals than I am) from Judge that resolves after all validations have returned from the server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep 50 is an arbitrary number, but it is merely a fallback to prevent an infinite loop.
I looked into a callback or promise on Judge's side, but I feel it would take a lot of supporting code to pass it to Fae. The AJAX can is written in vanilla JS and the call itself, where I'd usually receive the promise is in Judge as well.
I'll address @tshedor's comments and the tests I broke 😵 |
9248b4b
to
b29c820
Compare
Unique validation checks on forms require Judge to do an AJAX call. However in some cases the form is checked for validity and submitted before the AJAX response triggers the callback.
Since the AJAX call is from a 3rd party it's difficult to use callbacks or monitor the XHR object. This solution tracks the number of validations checks every 50ms until they all have responded. Then the form will submit or display errors accordingly.