Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] Wrong error message when using AtLeastOneOf #40082

Closed
@h4rvk4

Description

@h4rvk4

Symfony version(s) affected: 5.2.2+

Description
Since 5.2.2 the AtLeastOneOfValidator returns the wrong error message, when there is also an error on another field.
In 5.2.1 it returned correctly "this value should satisfy at least one of the following constraints: [1] Condition 1 [2] Condition 2"-
Now it returns "this value should satisfy at least one of the following constraints: [1] other field error [2] other field error".

How to reproduce
I made a small demo app: https://github.com/haruka/symfony_validator_test.

Possible Solution
Seems like the validator "steals" error messages from other field elements.

Additional context
Demo form:
field_1: NotBlank(message="field_1 is empty")
field_2: NotBlank(message="field_2 is empty")
field_3: AtLeastOneOf(Blank, Length(min=10, max=20))

Output from my demo app:

$ php run_test.php 
testWithNoData():
field_1: field_1 is empty
field_2: field_2 is empty

testWithFulldataAndInvalidField3():
field_3: This value should satisfy at least one of the following constraints: [1] This value should be blank. [2] This value is too short. It should have 10 characters or more.

testWithOnlyField3Data():
field_1: field_1 is empty
field_2: field_2 is empty
field_3: This value should satisfy at least one of the following constraints: [1] field_1 is empty [2] field_1 is empty

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions