-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Remove deleted elements before submit to avoid triggering validation #414
Remove deleted elements before submit to avoid triggering validation #414
Conversation
I have tried on a project and now the validation is not triggered when the collection item is marked for deletion. WDYT @VincentLanglet ? |
The bug was rely annoying, this is a great fix. I don't have a project to reproduce the bug and use the fix. I'm ok merging and releasing this |
It is really problematic to test this properly... form type is here, base templates are on the admin-bundle, BUT the form type widget is on the persistence bundles... So I guess the only way to test this is on the DoctrineORM/MongoDB persistence bundles, I can try it once released. |
Let me try one more way to delete those items. Wait a bit for the merge. |
No more changes needed, this is the cleaner solution I could found. I also tried to make it work somehow like this: https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php Where on preSubmit it only removed from the $form object, and on the submit it removed from the $data object, but it does not work on our use case. It complains about extra fields (data submitted contains more things that the $form is expecting, because we remove from $form first). There should be more pieces on Symfony code dealing with that, but I think it is not worth investigating more. Current behavior is buggy since it does not let you remove invalid items, and the fix improves that. EDIT: I guess the resizer from Symfony is expecting that when you remove an item, the $data will not contain it, it does not rely on a checkbox for removal, but the full removal on the frontend prior submit, that's why it works this way. |
I think this is the most correct solution @VincentLanglet . on Pre Submit we should make sure to remove extra data (data marked for removal) and to remove the form fields for that data (avoid adding them back to the form). Then onSubmit we don't have:
Validation will work for fields not removed, but will not be triggered for removed fields. |
I will try to prepare a test now for the doctrine orm admin bundle. |
Something like this: sonata-project/SonataDoctrineORMAdminBundle#1737 |
Subject
I am targeting this branch, because this is a bug fix.
Closes sonata-project/SonataAdminBundle#4348.
Changelog