CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

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

Open iRedds opened this issue 3 years ago • 2 comments

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 avatar Jul 09 '22 06:07 iRedds

I sent a PR, review please. #6340

ping-yee avatar Aug 04 '22 11:08 ping-yee