-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Constraints on unmapped fields are not validated as expected when using validation groups #58407
Comments
Can you create a small example application that allows to reproduce your issue? |
Looks like it works fine to me: IndexController
User
UserType
index.html.twig
You can check it here eliasfernandez@4d75337 `` |
Here's a small example application that demonstrates the issue: The form should validate that the code is not blank, but if you submit a blank code then there is no error. Then if you set validation_groups => ['Default'] and try to submit a blank code, then the validator works and you get an error. |
This is the expected behaviour. The
If the form is validated in the public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('code', TextType::class, [
'required' => false,
'label' => 'Verification Code',
'mapped' => false,
'constraints' => [
new Assert\NotBlank(groups: ['Registration']),
],
])
;
} Closing here as there is no bug to fix. Thank you for understanding. |
Right, ok, my bad. Thanks for the explanation. |
Symfony version(s) affected
7.1.5
Description
I have a user registration form, that is bound to a Doctrine user entity. In addition to the usual fields like first name, email, etc, I also have an unmapped field for a verification code. This code is not persisted with the user, but I want it to be validated when the form is submitted. I am also using a validation group with this form, because the user entity has many other fields that can be validated later, but are initially blank during registration.
I noticed that the constraints on the unmapped verification code field do not get checked as expected, even if I set the 'validation_groups' attribute to match the 'validation_groups' on the form. They will only get checked if I set 'validation_groups' to 'Default'.
This is unexpected and seems like a bug to me.
How to reproduce
User entity
My registration form:
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: