-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Improve error handling in Ajax #7922
Improve error handling in Ajax #7922
Conversation
To be able to properly fix this: sonata-project/SonataPageBundle#1495 (comment) We will need to properly work with the errors. Currently there is no context on what field is generating the error. On 3.x branch of AdminBundle, due to this return null: https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Controller/CRUDController.php#L1712-L1722 we were relying on html generated for the error page. So, in 3.x of PageBundle: If you are calling the createAction via ajax and the response is Success, it will arrive in the form of json, BUT if the response was failure, it was arriving in the form of HTML with the errors already in place. It looks very bad, but now, in 4.x always the response is get via json, so without this PR it is impossible to know where to place each error. This PR gives each error a key which is the ID of the form field. (Also each field can have multiple errors, so we need to take into account that too. |
wdyt @VincentLanglet ? Do you know any other solution for this? |
src/Controller/CRUDController.php
Outdated
return $errors; | ||
} | ||
|
||
private function buildName(FormInterface $form): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, the same with buildId, it can't be reused by symfony. It is built on createView
thanks to: https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php#L49
I know that this needs probably to move some logic outside crud controller and test it and all, but does the code look good or should I find another way? @VincentLanglet |
dee070b
to
03c9962
Compare
Seems an OK strategy to me if it works for you. |
Co-authored-by: Vincent Langlet <[email protected]>
03c9962
to
45b892f
Compare
e0c214c
to
2c93565
Compare
This should be ready, have added tests, changelog and upgrade note. Also took care of all comments and tried the compat with page bundle. In the changelog and in the upgrade note is mentioned the possible (but unlikely) bc break. Unlikely because I dont think anyone is using sonata as an api (and if they do, they probably got the same problems as we did on the page bundle: error output was broken) |
Subject
I am targeting this branch, because error output for ajax calls is kinda broken atm and it is needed for page bundle.
Changelog