I have the following situation on a web application (javascript-jQuery):
- A form using validator of https://jquerytools.org/
- In the form there is a [required] masked input (bank account) from https://github.com/RobinHerbots/Inputmask, which throws a request on server on change event and during the request the input is disabled to avoid modifications.
When the form is submitted, sometimes, when the bank account is empty, the validation "required" is not checked. After a crazy debug, I've seen that the input mask control, is firing a change event, and so, the request is throwed to the server (so the input is disabled), and the validator doesn't validates the required, because it has a condition that the disabled fields are not validated.
I would to "pause" the validation until all requests are finished, but I haven't found the way to do it outside the library. Any idea of how to solve this problem wihtout modifying the external libs ("jquery inputmask" and "jquery tools")?
Finally I've choosed the following solution:
When the submit button is pressed, check if there are pending requests before submitting. I use a javascript interval to check every 200ms (and during a max of 10 intervals to avoid unsubmitted forms by erroneous tracking).
On the other hand, I check if the form is submitting before send a rule request on the server. If the form is submitting, I don't calculate the rule.
I post the code adapted to understand.
Function to check the form submit:
Function that executes server rules on input changes: