Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make validators less painful to use #666

Open
tim-evans opened this Issue · 5 comments

4 participants

@tim-evans
Collaborator

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.

@mitchless
Collaborator

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

@sevifives
Collaborator

What an appropriate issue number.

@hungle

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

@mitchless
Collaborator

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

@tim-evans
Collaborator

@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:

form: SC.View.design({

  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
     }
  },

  username: SC.TextFieldView.design({
    validator: SC.EmailValidator
  }),

  password: SC.TextFieldView.design({
    validator: SC.PasswordValidator,
    isPassword: YES
  }),

  submit: SC.ButtonView.design({
     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
Something went wrong with that request. Please try again.