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]: Model::getMessages does not allow filtering messages by array of fields #16265

Closed
SliceOfLife opened this issue Jan 17, 2023 · 1 comment
Assignees
Labels
bug A bug report status: medium Medium

Comments

@SliceOfLife
Copy link

Describe the bug
We can validate Model by several fields at once, for example, by Uniqueness validator. But if the filter is producing an error, we can't get only this message by calling Model::getMessages(['field1', 'field2']) because internal implementation allows only strings as messages filter:

    public function getMessages(var filter = null) -> <MessageInterface[]>
    {
        var message;
        array filtered;

        if typeof filter === "string" && !empty filter {
            let filtered = [];

            for message in this->errorMessages {
                if message->getField() == filter {
                    let filtered[] = message;
                }
            }

            return filtered;
        }

        return this->errorMessages;
    }

To Reproduce
Steps to reproduce the behavior:

$model->getMessages(['login', 'loginType']); // Returns all Model messages, not just the ones I need

Provide minimal script to reproduce the issue

class User extends Model
{
	public function validation(): bool
	{
		$validator = new Validation();
		$validator->rules(['login', 'loginType'], [
			new Validation\Validator\Uniqueness([
				'model' => $this,
				'message' => 'Login already in use',
			]),
		]);

		return $this->validate($validator);
	}
}

Expected behavior
I expect to get messages related to the specified pair of fields.

Details

@SliceOfLife SliceOfLife added bug A bug report status: unverified Unverified labels Jan 17, 2023
@niden niden self-assigned this Jan 20, 2023
@niden niden mentioned this issue Sep 30, 2023
5 tasks
@niden niden added status: medium Medium and removed status: unverified Unverified labels Sep 30, 2023
@niden
Copy link
Member

niden commented Oct 1, 2023

Resolved in #16446

Thank you @SliceOfLife

@niden niden closed this as completed Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
Status: Released
Development

No branches or pull requests

2 participants