0
votes

Let say I have a "sing up" form with a mix of client side and server side validation. This is the validation for the email field:

  • Client side validation: required & valid
  • Server side (async) validation: unique

The way I would like it to work is for the client side validation (required & valid) to be executed as fast as possible (no throttling - input "afterkeydown") while the server side validation is throttled and executed when the user stops typing.

The problem is that Knockout "throttle extender" returns a new dependentObservable and all the validations are now throttled. I cannot apply throttling individually to the different validation parts.

I thought of creating a second computed email only for the unique/throttled validation but it doesn't make sense as it fires even if the email is not valid and it makes the code more complicated.

Any idea how to make this work without making the solution too crappy?

Edit #1

A good example of what I'm trying to do is the "sign up" form on Twitter website: https://twitter.com/signup. When entering a username, Twitter will automatically check the availability (after some throttling) and give feedback (without having to leave the field).

1
Have you tried doing validation on the whole object that only fires once the other validators are ok?PW Kad
May I just suggest that keystroke-by-keystroke validation on something like an email address is pretty user-hostile? You can't really determine the validity of an email address until the user has finished typing it; throwing up an error message while the user is in the process of entering something that will eventually be valid is pretty offputting. Don't validate the field until the user tries to leave it.ebohlman
@ebohlman Let me disagree with you. I think the user should have feedback as soon as possible. Twitter seems to share my opinion: twitter.com/signupW3Max

1 Answers

0
votes

I ended up modifying Knockout-Validation.

I didn't want to throttle the whole validation for a specific field (only the async part). This can't be done with the throttle provided by Knockout framework. In this case, it is a validation concern (throttling) so I think it makes sense to include it in the validation framework.

I will try to make a pull request on the Knockout-Validation repo and post back the result here.