aurelia / validatejs

Enables expressive validation using decorators and/or a fluent API.
MIT License
22 stars 23 forks source link

Feature request: subproperty validation #98

Closed JeroenVinke closed 8 years ago

JeroenVinke commented 8 years ago

I pull in some entities through breeze that have navigation properties, and I need to validate properties on the navigation property. So it would help me big time if this could be supported:

    ValidationRules
    .ensure('user.lastName').required()
    .on(this);

https://gist.run/?id=8ead16d0aa96a1c59b14eecbc59538fd

devanp92 commented 8 years ago

@JeroenVinke I found this to work (https://gist.run/?id=89fd2c2e4ddc195c19f5717920312a2f).

ValidationRules
.ensure('lastName')
.required()
.on(this.user);

Since ensure requires a property of an object, make the validation rules check this.obj (this.user in your case). Not sure if this is the correct way - but might be a workaround.

JeroenVinke commented 8 years ago

@devanp92 Thanks, I'm aware of that, but this feature request is mainly for doing things like this:

    ValidationRules
    .ensure('password.original').required()
    .ensure('lastName').required()
    .on(this.user);

where one property exists directly on the object and one property exists in a subproperty. The binding engine is awesome at parsing expressions like password.original so it should be able to do this automagically :smile:

devanp92 commented 8 years ago

@JeroenVinke Gotcha. That sounds like a useful feature to add! :+1:

bobpardoe commented 8 years ago

Any idea when this might be available? I want to start using the spoonx orm but I can't until model.property works for the ValidationRules

jdanyow commented 8 years ago

main repo has same issue