Yeah, I explored this a while back. It's confusing, because there are essentially three levels of enforcement:
1) Real-time input enforcement. Some inputs support a regex pattern, that controls what the user can actually type in the field.
2) Field & form validation (provided by iron-validator, for example). By default, this is invoked _when the user presses submit_.
3) The kind of validation you're talking about, using an async web request.
In the case of validating using a webservice, you don't want to start when the user presses the submit button. You probably want to fire off a request when the input field loses focus. (Another, slightly more aggressive option is to fire off the request when the user stops typing for a certain period of type, like 500ms. However, I was unable to get this to work smoothly when I tried it.)
It can be nice for the user if you do async form validation, so that you can enable/disable the submit button based on whether the form is valid, instead of waiting until they click the button and then pointing out the issue.
The devil is in the details, but I think one working pattern is to do something like this:
- Whenever the user blurs a text area, or changes the state of a checkbox or option, etc., perform a validation check:
- If the field that changed requires remote validation, fire off a web request and continue this process when the response comes back.
- Check the validity on all of the fields, and enable/disable the submit button accordingly.
Ideally, you'd do some kind of periodic checks as well when the user isn't typing. Otherwise, the user can finish entering data in the last input field, and sit there waiting for the submit button to be enabled, which won't happen until they click elsewhere on the screen. But as I said, I didn't get that working when I was playing with this.
Hope that helps.
Cheers,
Arthur