N
N
Ninazu2020-05-20 15:07:12
symfony
Ninazu, 2020-05-20 15:07:12

How to validate a group of optional fields?

How to make it so for queries like:

{
    name: "value",
    field1: "value"
},
{
    name: "value",
    field2: "value"
},
{
    name: "value",
    field1: "value",
    field2: "value"
},
{
    name: "value"
}

The first three passed validation and the last one did not, since there is not a single one from the group of optional fields.

I tried to write YAML for simply optional fields, but how to make require at least one of them?

Collection:
  fields:
    name:
      - Required:
          - NotBlank: ~
          - Type:
              type: 'string'
    field1:
      - Optional:
          - NotBlank: ~
          - Type:
              type: 'string'
    field2:
      - Optional:
          - NotBlank: ~
          - Type:
              type: 'string'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question