ember-cp-validations icon indicating copy to clipboard operation
ember-cp-validations copied to clipboard

Allowing child validations to be specified with on or excludes

Open aaronbhansen opened this issue 8 years ago • 4 comments

We have a situation where we have a model with multiple has-many child relations we would like to validate on, but on specific pages, exclude a some of the child has-many validations.

The use case is, we are creating this parent model and all of the related child models through several pages in a wizard process. On the last page everything should be valid including the children, but as they are adding or editing specific parts on each part of the wizard, only the elements related to that specific page should be validated.

It would be great to be able in the validate options for excludes or on, to be able to specify which has-many or belongs-to validates you want to exclude. For example, if you could pass something into the excludes to ignore children.

Parent model: Load
Load has many: Operations
Operation has many: Items
Item has validations for quantity, name, allowed

load.validate({ excludes: ['operations.items.quantity', 'operations.items.allowed'] })

or even better to use ember shortcuts

load.validate({ excludes: ['operations.items.{quantity,allowed}'] })

In these examples above, maybe the name is created in the first page of the wizard, but quantity isn't assigned until other parts of the wizard are completed (because other data points are needed on the following steps). It would be great if you could specify on the parent model which child validations to skip.

This can kind of be worked around today by having a property on load that the children check, or specifically setting a property on the children before validating that disables the child validation, but it would be great if you could specify everything at the parent validation call.

Any thoughts on adding such a feature?

aaronbhansen avatar Apr 14 '16 16:04 aaronbhansen

I definitely understand the need for this use case but the current implementation and how the CPs are structured, this wouldn't be a simple task. Once I have some time, Ill explore this and see what I can do but as of right now, your best bet is to use disabled, dependentKeys and custom validators.

offirgolan avatar Apr 14 '16 17:04 offirgolan

Sounds good. Looking through the code I couldn't see an easy way to implement it either. Be great to have, in the meantime I'll work around it.

aaronbhansen avatar Apr 14 '16 17:04 aaronbhansen

I definitely can see this as a very valid use case, but understand that it's difficult to get implemented.

blimmer avatar Apr 17 '16 01:04 blimmer

@offirgolan do you think this would be any easier to implement with some of the validation work on isDeleted for checking what to validate?

aaronbhansen avatar Aug 22 '16 18:08 aaronbhansen