-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fix: Validation. Error key for field with asterisk #5609
Fix: Validation. Error key for field with asterisk #5609
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
The error keys (and values) will be changed. It should be documented in changelog. |
@kenjis added |
Isn't this PR a breaking change? The following test will fail. --- a/tests/system/Validation/ValidationTest.php
+++ b/tests/system/Validation/ValidationTest.php
@@ -851,6 +851,10 @@ final class ValidationTest extends CIUnitTestCase
'name_user.2' => 'The name_user.* field may only contain alphabetical characters.',
'contacts.friends.0.name' => 'The contacts.*.name field is required.',
], $this->validation->getErrors());
+ $this->assertSame(
+ 'The id_user.* field must contain only numbers.',
+ $this->validation->getError('id_user.*')
+ );
}
public function testRulesForSingleRuleWithSingleValue(): void |
How about these?
|
I'm not sure about the behavior of |
Technically, this is a potentially breaking change. However, I believe the chances this change will break apps is low. So, this must be disclosed in the changelog with a caveat for those using |
If I want to check the result, do I write code like this? if (
$this->hasError(''users.friends.0.name')
|| $this->hasError(''users.friends.1.name')
|| $this->hasError(''users.friends.2.name')
) {
...
} |
@kenjis Wait, I was only talking about getError(). |
@iRedds Can you rebase and resolve conflicts? |
Signed-off-by: Andrey Pyzhikov <[email protected]>
Signed-off-by: Andrey Pyzhikov <[email protected]>
Signed-off-by: Andrey Pyzhikov <[email protected]>
Signed-off-by: Andrey Pyzhikov <[email protected]>
Signed-off-by: Andrey Pyzhikov <[email protected]>
d515242
to
1336539
Compare
@kenjis Yes i can |
@iRedds Thanks! |
Now the error array is like this: [
'users.friends.0.name' => 'The users.*.name field must be at least 4 characters in length.',
'users.friends.2.name' => 'The users.*.name field is required.',
] But would it be easier to use? [
'users.*.name' => [
0 => 'The users.*.name field must be at least 4 characters in length.',
2 => 'The users.*.name field is required.',
]
] What do you think? |
@kenjis Here we lose the 'users' => [
'friends' => [
0 => [
'name' => 'correct',
],
],
'enemies' => [
0 => [
'name' => null,
],
],
] Although my example looks like an attempt to pull an owl on a globe. |
I don't know we need to support such a use case, but then: [
'users.*.name' => [
'friends' => [
0 => 'The users.*.name field must be at least 4 characters in length.',
2 => 'The users.*.name field is required.',
],
]
] |
Since I don't use CI. It's hard for me to imagine how it would be convenient for a real project to provide errors. |
Description
Now, when validating a multidimensional array using a wildcard, only the last error is saved. Therefore, it is impossible to determine which field the error belongs to.
This PR changes behavior. Errors have a corresponding key.
Checklist: