Make validators less painful to use #666

tim-evans opened this Issue Dec 22, 2011 · 5 comments

4 participants

SproutCore member

I'd like for validators to work well, and have documentation of how to use them. I've had to read through the source to even determine how to use them, and have had to cobble together a solution for triggering validation in an ad-hoc manner to make use of them. Some work here on making validators easy and painless to use would be welcome.


I've been using them a bit in my project. I can help out here.


What an appropriate issue number.


I agree. If anyone have ideas on how to improve it, I can help out with the code changes.


@tim-evans Can you give me some examples of how you're using them ad-hoc?

SproutCore member

@mitchless, sure!

We're using it for a login view, where each field gets validated on pre-submit. If a field is invalid, then we show a non-popup that points to the field that didn't validate correctly.

The form looks something like:


  validate: function () {
     if (this.get('username').validateSubmit() !== SC.VALDIATE_OK) {
       // do something
     } else if (this.get('password').validateSubmit() !== SC.VALDIATE_OK) {
       // do something
     } else {
       // fire submit on some target / action

    validator: SC.EmailValidator

    validator: SC.PasswordValidator,
    isPassword: YES

     targetBinding: SC.Binding.oneWay('.parentView'),
     action: 'validate'

This is merely an approximation of what we have in our app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment