-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
validation issue after removeElement() #5609
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
The validation is applied during the binding of the form (it is done during the |
Ok I was confused on that. |
@arnaugm you should use a listener on one of the form events. It could be either on PRE_BIND if you want to remove the empty child in the client data (the format submitted by the user) or on POST_BIND (with a higher priority than the ValidatorListener so that it runs before the validation) if you prefer removing the element in the app data (your entities) |
That's what I'll do then. Thanks! |
I have a form with a collection of elements. For usability I create a first blank element of the collection for the user. I want to validate that the collection has at least one element, so in case the user leaves this first element blank, I remove it with removeElement() before calling $form->isValid().
My surprise is that even though the element is not any more inside the collection, the validation doesn't take it into account and keeps thinking that there is still one element in the collection, so the validation pass when it should fail.
Am I missusing the remove feature?
I verified that if I remove the element using the application and submit the form with a real empty collection, then the validator fails as expected.
I'm in S2.1.1
The text was updated successfully, but these errors were encountered: