Closed
Description
PHP 7
Using Symfony\Component\Validator\Constraints\Collection;
I'm using Symfony 3.1 and I hope I'm not doing something wrong. When I validate a field, it doesn't stop after the first violation. Example :
$errors = $val->validate(
$info,
new \Symfony\Component\Validator\Constraints\Collection([
'fields' => array(
'specialKey' => array(
new NotBlank(),
new Length(['min' => 8,'max' => 20]),
new Regex(['value' => "/^[A-Za-z]*$/"]),
)
),
'allowExtraFields' => true,
])
);
I'm getting :
'This value is too short. It should have 8 characters or more.'
'This value is not valid.'
I found a walk-around for those who are interested :
$errors = $val->validate(
$info,
new \Symfony\Component\Validator\Constraints\Collection([
'fields' => array(
'specialKey' => array(
new NotBlank(['groups' => 'groupe1']),
new Length(['min' => 8,'max' => 20,'groups' => 'groupe2']),
new Regex(['value' => "/^[A-Za-z]*$/",'groups' => 'groupe3']),
)
),
'allowExtraFields' => true,
]),
new GroupSequence(array('Default','groupe1','groupe2','groupe3'))
);