Skip to content

Multiple conditionally required fields validation #725

Open
@nicpalard

Description

@nicpalard

Environment

  • Ember Version: 3.4.4
  • Ember CLI Version: 3.4.4
  • Ember CP Validations Version: 4.0.0-beta.10

I have done several simple validations that are working perfectly but now I need to perform a more complex validation over 3 conditionally required fields with the following logic:

I have 3 fields that are conditionally required based on each others value:

  • Field A (a belongsTo field) is optional but should be specified if field B is empty
  • Field B (a belongsTo field) is also optional but should be specified alongside field C if field A is empty
  • Field C (a string attribute) is optional but should be specified when field B is specified.

In other words one should specify A or (B and C).
Also: A and B and C is not valid

I can not seem to find any example for my use case. I have read about custom validators but I can't seem to make it work for that particular logic.
With custom validation I can partially achieve what I want to but how can I trigger the others field to be validated when a specific field changes ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions