Skip to content

Many constraints validation per fields #24

Description

@silasrm

Hi @Gregwar,

I've a case with 2 constraints but only 1 is returned in check:

$form2->addConstraint('quantidade_assentos', function($form) {
            if (empty($form->getValue('quantidade_assentos'))) {
                return 'Quantidade de assentos é obrigatória!';
            }

            return null;
        });

        $form2->addConstraint('quantidade_assentos', function($form) {
            if (!is_numeric($form->getValue('quantidade_assentos'))) {
                return 'Quantidade de assentos deve ser número inteiro!';
            }

            return null;
        });

Dump of getFields():

"quantidade_assentos" => NumberField {#613 ▼
    #type: "number"
    #min: "1"
    #max: null
    #step: "1"
    #name: "quantidade_assentos"
    #index: null
    #hook: null
    #attributes: array:3 [▶]
    #value: ""
    #required: true
    #regex: null
    #minlength: null
    #maxlength: null
    #prettyname: null
    #readonly: false
    #valueChanged: true
    #constraints: array:2 [▼
      0 => Closure {#606 ▶}
      1 => Closure {#605 ▶}
    ]
    #mapping: null
    #language: English {#625 ▶}
  }

Dump of errors:

array:1 [▼
  0 => Error {#604 ▼
    -field: NumberField {#613 ▶}
    -message: array:2 [▼
      0 => "value_required"
      1 => "quantidade_assentos"
    ]
    #language: English {#625 ▶}
  }
]

In my view, there should be 2 errors because a empty value "" is catched in both constraints.

Any error in my logic?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions