Skip to content

Bug: Custom validation error for a field with an asterisk. #6245

Closed
@iRedds

Description

@iRedds

CodeIgniter4 Version

dev

What happened?

If you specify a custom error message for a field with an asterisk, the default error text will be used.
This is due to the fact that a field without an asterisk is passed to generate an error (it contains the full path of the key)

Steps to Reproduce

$data = [
    'user' => [
        ['name' => null],
        ['name' => null],
    ]
];

$validator = Services::validation();

$validator->setRules(['user.*.name' => 'required'], ['user.*.name' => ['required' => 'Required']]);

$validator->run($data);

dd($validator->getErrors());
// array (2) [
//     'user.0.name' => 'The user.*.name field is required.'
//     'user.1.name' => 'The user.*.name field is required.'
// ]

Expected Output

array (2) [
    'user.0.name' => 'Required'
    'user.1.name' => 'Required'
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions