-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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]: form entity isn't passed to validator #15567
Comments
Shouldn't the validator be attachted to field instead? |
No, because you set validators for the field in PeronValidator. It's better to separate validation rules in a class. That way you can use that validation everywhere like in Forms and Models. |
I see. Slightly different behavior here on 4.1.0. I've created a validation class and attached it to a form and to the related model. No problems on adding a new (non-existing) |
Adding is not a problem because the entity is in TRANSIENT state. Fetch an existing one and don't change the name and submit the form. Then it doesn't validate. And that's the problem, because the form object doesn't pass his entity to the validation. And the Uniqueness validator checks on the state of the entity. |
BTW: I would use But as the problem happens in model validation, does it really depends on form? I mean, form validation passes and in Edit:
|
Resolved in #15568 |
When setting an entity to a form on construction and calling isValid($data), the entity isn't passed to the validator. The only entity that is passed, is the entity that is passed with isValid($data, $entity). But you shouldn't do this, because you already pass this entity to the form on construction.
To Reproduce
Steps to reproduce the behavior:
Person.php
PersonValidator.php
PersonForm.php
PersonController.php
Expected behavior
If you run this edit action and just hit save and don't change anything. It should produce the success message Person saved!.
But it doesn't. It gives the error message Person name must be unique!.
If you change the isValid() line to the line below, it works.
Details
The text was updated successfully, but these errors were encountered: