-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
"cascade_validation" option not working at third level in beta4 #5204
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
Comments
I can confirm this issue. You can work around that by setting the |
Problem only half solved. Now my validation.yml file looks like this Manager\UsersBundle\Entity\User: properties: name: - NotBlank: message: The name can not be blank phones: - Valid: ~ Manager\UsersBundle\Entity\Phone: properties: number: - NotBlank: message: The number can not be blank The validation is now correctly executed because $form->isValid() returns false. |
Related to that but not sure if the issue is exactly the same. Manager\UsersBundle\Entity\User: properties: websites: - Count: min: 1 minMessage: You must add at least one website emails: - Count: min: 1 minMessage: You must add at least one email This is the doctrine configuration in User.orm.yml Manager\UsersBundle\Entity\User: type: entity repositoryClass: Manager\UsersBundle\Repository\UserRepository table: users fields: id: id: true type: integer unsigned: false nullable: false generator: strategy: AUTO username: type: string length: 255 fixed: false nullable: false unique: true password: type: string length: 255 fixed: false nullable: false salt: type: string length: 255 fixed: false nullable: false created: type: datetime nullable: false gedmo: timestampable: on: create updated: type: datetime nullable: false gedmo: timestampable: on: update manyToOne: group: targetEntity: Group inversedBy: users joinColumns: group_id: referencedColumnName: id nullable: false oneToMany: phones: targetEntity: Phone mappedBy: user cascade: ["persist", "remove"] orphanRemoval: true websites: targetEntity: Website mappedBy: user nullable: true cascade: ["persist", "remove"] orphanRemoval: true emails: targetEntity: Email mappedBy: user nullable: true cascade: ["persist", "remove"] orphanRemoval: true lifecycleCallbacks: { } and the related entities Manager\UsersBundle\Entity\Website: type: entity repositoryClass: Manager\UsersBundle\Repository\WebsiteRepository table: websites fields: id: id: true type: integer unsigned: false nullable: false generator: strategy: AUTO url: type: string length: null fixed: false nullable: false isMain: type: boolean length: null fixed: false nullable: true column: is_main created: type: datetime nullable: false gedmo: timestampable: on: create updated: type: datetime nullable: false gedmo: timestampable: on: update manyToOne: user: targetEntity: User inversedBy: websites joinColumns: user_id: referencedColumnName: id nullable: false lifecycleCallbacks: { } Manager\UsersBundle\Entity\Email: type: entity table: emails fields: id: id: true type: integer unsigned: false nullable: false generator: strategy: AUTO email: type: string length: null fixed: false nullable: false isMain: type: boolean length: null fixed: false nullable: true column: is_main created: type: datetime nullable: false gedmo: timestampable: on: create updated: type: datetime nullable: false gedmo: timestampable: on: update manyToOne: user: targetEntity: User inversedBy: emails joinColumns: user_id: referencedColumnName: id nullable: false lifecycleCallbacks: { } |
Confirmed that in RC1 the problem is not solved. |
Would you consider this issue as a 2.1 blocker? @fabpot @bschussek |
The problem is still there in 2.1.1, any clue about where is the issue? |
I've discovered that the second problem in fact has nothing to do with the first, I moved to a new issue #5609. |
Hi @Tobion, you confirmed the issue right? As @bschussek didn't make any comment on that I'm starting to think that's a problem on my side. I really need to solve that, I have a complex form and if I have to implement myself the validation it becomes a nightmare. By now I have js validations, but I don't feel comfortable only with them. Your workaround worked but the errors don't appear, which is not much better, because the form is not saved and the user doesn't know why. Any idea? Thank you. |
A form of mine with 3 levels of nesting works fine with the |
Yes, I was already following your advice. |
the same problem, 2 levels work fine, 3 does not work. I have tests also by using I have removed
Form class
|
I had the same issue and I found out that the My case: I have a Project form type, which has a collection of Article form types, which has a collection of ProductionQuantity form types. And one field of the ProductionQuantity form type should be validated. Here my form classes in short: class ProjectType extends \Symfony\Component\Form\AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('articles', 'collection', array(
'type' => new ArticleType(),
'cascade_validation' => true, // <- this is needed to get the grandchild validated!!
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Project',
'cascade_validation' => true,
));
}
}
class ArticleType extends \Symfony\Component\Form\AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('productionQuantities', 'collection', array(
'type' => new ProductionQuantityType(),
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Article',
'cascade_validation' => true,
));
}
}
class ProductionQuantityType extends \Symfony\Component\Form\AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('year', 'integer'); // this should be validated !!
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'ProductionQuantity'
));
}
} It was hard to figure out that the If not, this behaviour should be documented. I tried already to find the right place in the documentation, to add this hint. But I do not know where. Maybe someone could give me a suggestion ;) I am using version 2.3.* |
Wow! Setting the On the other hand, trying to perform the same cascading validation with Correlative indexes with the
Non-correlative indexes with the
With the Symfony 2.3.2 |
Some related issue: 3rd level validation doesn't work when there is a Form Listener with Without listener the field is validated correctly. |
@ping webmozart |
ping @webmozart :) |
Should we document the need for the duplicate cascade_validation setting? |
The "cascade_validation" constraint is now deprecated. See #12237 |
This PR was merged into the 2.8 branch. Discussion ---------- [Form] Deprecated "cascade_validation" | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #11268 (requires explicit work though) | License | MIT | Doc PR | TODO This is #12237 rebased on 2.8. The "cascade_validation" option was designed for a 1% use case and comparatively used way too often when the `Valid` constraint should have been used instead. Also, there seem to be bugs with that option (#5204). The option is now deprecated. When using the 2.5 Validator API, you can set the "constraints" option of the respective child to a `Valid` constraint instead. Alternatively, set the constraint in the model (as most people hopefully do). Commits ------- 6c554c6 [Form] Deprecated "cascade_validation"
I have a form with three levels of nesting. Imagine a group, which has users, which have phone numbers.
The GroupType has the option cascade_validation => true, and a collection of UserType.
The UserType has the option cascade_validation => true, and a collection of PhoneType.
I have validations defined for the three entities in the file validation.yml, simple NotBlank validations.
The validations of Group and User work perfectly and I get the error when I try to submit the form with blank fields, but if I let the fields of the Phone empty, the form goes ahead and causes a db error because is receiving a null for a non null column.
The issue is in beta4, I haven't had time to test it in the RC1, even I haven't seen anything related in the change log.
The text was updated successfully, but these errors were encountered: