Skip to content
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

Merged
merged 4 commits into from
Dec 7, 2017

Conversation

jamesmk
Copy link
Member

@jamesmk jamesmk commented Oct 16, 2017

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.

Copy link
Contributor

@tshedor tshedor left a 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 () {
Copy link
Contributor

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 () {
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Member Author

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.

@jamesmk
Copy link
Member Author

jamesmk commented Oct 18, 2017

I'll address @tshedor's comments and the tests I broke 😵

@jamesmk jamesmk force-pushed the 69450-validation-fix branch from 9248b4b to b29c820 Compare December 7, 2017 00:33
@jamesmk jamesmk merged commit 7ad85fc into v1.7 Dec 7, 2017
@jamesmk jamesmk deleted the 69450-validation-fix branch December 7, 2017 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants