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

Way to add error with custom value path #651

Open
vjik opened this issue Jan 19, 2024 · 2 comments
Open

Way to add error with custom value path #651

vjik opened this issue Jan 19, 2024 · 2 comments
Labels
status:ready for adoption Feel free to implement this issue. type:enhancement Enhancement
Milestone

Comments

@vjik
Copy link
Member

vjik commented Jan 19, 2024

In rule handlers Result::addError() is added error message to current key and value path define path into key. Need ability to add error with globally path.

Example:

$result = (new Validator())->validate(
    data: ['a' => 1, 'b' => 2],
    rules: [
        'a' => new Callback(function(){
            $result = new Result();
            $result->addError('message', valuePath: ['b']);
            return $result;
        })
    ],
);

// Errors:
// ['a.b' => ['message']]

Need additional ability add error to key b. May be implement it via adding method addError() to validation context object.

@samdark
Copy link
Member

samdark commented Jan 19, 2024

What's the use-case?

@samdark samdark added the type:enhancement Enhancement label Jan 19, 2024
@vjik
Copy link
Member Author

vjik commented Jan 19, 2024

What's the use-case?

Forms: add error to another field or add error without fields (common errors).

@samdark samdark added the status:ready for adoption Feel free to implement this issue. label Jan 19, 2024
@samdark samdark added this to the 2.0 milestone May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue. type:enhancement Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants