Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
iRedds opened this issue Jul 9, 2022 · 1 comment · Fixed by #6378
Closed

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

iRedds opened this issue Jul 9, 2022 · 1 comment · Fixed by #6378
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@iRedds
Copy link
Collaborator

iRedds commented Jul 9, 2022

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'
]
@iRedds iRedds added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 9, 2022
@ping-yee
Copy link
Contributor

ping-yee commented Aug 4, 2022

I sent a PR, review please. #6340

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
2 participants