aurelia / validation

A validation plugin for Aurelia.
MIT License
132 stars 129 forks source link

Simplify validation DSL #223

Closed stalniy closed 8 years ago

stalniy commented 8 years ago

I see that there is a big/complex DSL around validation. What about adding ability of something like this:

class UserProfile { 
  @ensure({ presence: true, minlength: 5 })
  name = '';

  @ensure({ presence: true, if: 'isAdult' }) 
  // or @ensure({ presence: true, if: u => u.age >= 18 })
  // or @ensure({ presence: true, unless: u => u.age < 18 })
  profession = null;

  isAdult() {
    return this.age >= 18;
  }
}

Doesn't it seem simpler or more straightforward than current version?

class UserProfile { 
  @ensure(it => it.isNotEmpty().hasLengthBetween(3,10))
  name = '';

  @ensure(it => it.if(u => u.isAdult()).isNotEmpty().endIf()) 
  profession = null;

  isAdult() {
    return this.age >= 18;
  }
}
plwalters commented 8 years ago

Thanks for submitting this / commenting on this. At this time we are closing this because we have completely re-written and are deprecating the previous feature set. If you feel this should be re-opened please feel free to review this blog post and submit either again on this repository, or on the new validatejs bridge repository

Thanks again!

plwalters commented 8 years ago

As a note the API for validation is changing so any thoughts welcome here - https://github.com/aurelia/validatejs/issues/17