-
-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependent keys for custom validators #27
Comments
I believe we have two options here. The first is to expand the var Validations = buildValidations({
x: [ validator('x-custom'), validator('dependent', { on: ['foo', 'bar.x']}) ]
}); The second, is to expose a public api to add custom dependent keys. var Validations = buildValidations({
x: validator('x-custom', { dependentKeys: ['foo', 'bar.x'] })
}); @blimmer @stefanpenner thoughts? |
@offirgolan One thing to keep in mind is that a validator may be dependent on another validator or a property on the model. For instance, the One use case I'm thinking of is "make sure this model has least one hasMany model with this property". The workaround today could be to create a computed property on the model: hasAtLeastOneFeaturedPost: computed('posts.@each.isFeatured', function() {
return _.some(this.get('posts'), (p) => p.get('isFeatured'));
} And then validate that that is true, but it would be nice to be able to express that with just a validator. var Validations = buildValidations({
featuredPost: validator('has-some', { collection: 'posts', attribute: 'isFeatured' })
}); |
Im not sure I follow... Wouldn't you be able to achieve the same functionality by doing something like this var Validations = buildValidations({
featuredPost: validator(function(value, options, model) {
return _.some(model.get('posts'), (p) => p.get('isFeatured'));
}, { dependentKeys: ['posts.@each.isFeatured'] })
}); |
Why not let custom validators use fields on the model at their discretion? This would let me support a lot of more "meta" type validations that I have had to deal with.
Looking at https://github.com/offirgolan/ember-cp-validations/blob/v1.1.0/addon/utils/validations-factory.js#L176-L203 I can see that each built-in validator that needs custom dependent keys is hard-coded. Is a general API for this being discussed?
The text was updated successfully, but these errors were encountered: