Skip to content

Validation doesn't throw violation to good form in collection form #11275

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

Closed
Sorendil opened this issue Jul 2, 2014 · 1 comment
Closed

Validation doesn't throw violation to good form in collection form #11275

Sorendil opened this issue Jul 2, 2014 · 1 comment

Comments

@Sorendil
Copy link

Sorendil commented Jul 2, 2014

Hi everybody.

I have a problem with the validation message of my form GameType(). This Type ambed a collection of GameOnConsoleType().

By following the doc : http://symfony.com/doc/current/cookbook/form/form_collections.html, my form works fine except validation messages.

So, in my game form, I add 1 object GameOnConsole. I get the prototype html and replace name by 0. I add another object GameOnConsole so I replace name by 1.

But now, if I delete the first GameOnConsole, my form will have only one GameOnConsole with index : 1.

If this GameOnConsole violates a constraint, the violation will try to reach Object(Symfony\Component\Form\Form).data.gameOnConsoles[0]... which does not exist, because my GameOnConsole has the index 1.

The version of Symfony is 2.5.

I think it is a bug, the validator should use indexes that we passed in the form and not recalculate them.

Thanks !

@stof
Copy link
Member

stof commented Jul 2, 2014

the validator uses the index in your Doctrine collection, because it runs on the collection. The issue is that when using adders and removers on the parent object (which is needed to handle relations properly in entities), the index in the collection might not match the index in the form.

Object(Symfony\Component\Form\Form).data.gameOnConsoles[0] exists, as this is a property path in the object itself (.data gets the data of the form).

Closing as duplicate of #7468

@stof stof closed this as completed Jul 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants