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
$event->getData() returns null for an embedded form #6128
Comments
Hi, thank you for reporting this issue! Could you please publish a fork of symfony-standard that reproduces your problem? In general, this functionality is known to work. |
Ok, I will prepare it when I have a bit of time... Thanks! |
Any news? |
Wow, I didn't remember this, to be honest. I close the issue because I find too difficult to get the time... I'll reopen if I have the time to review this. |
GitHub never forgets ;) |
for anyone else that runs across this. I ran into the same issue in symfony 2.1 but performed the same test in 2.3 and it was fixed. |
so, what should we do if we are working with symfony2.1? is there any solution for that? |
@p-shad your solution is updating to a maintained version of Symfony. The 2.1 serie reached its end of maintenance several months ago |
Hi, i'm on Symfony 2.3.9 and the issue exposed here is still reproducible so it already exists and i'm suffering from it. Could you please reopen that issue? class ParentFormType extends AbstractType
/*Each one of bellow calls returns NULL
|
Also having this issue |
Can some do what @webmozart proposed more than a year ago? |
please @sibok close your issue 10300 as it is related to this and is the same issue #10300 |
@cordoval this issue has been closed 11 months ago |
and I don't see the point of closing an opened issue and reopening a closed one. Why not keeping them in their current state ? |
trying to reproduce here https://github.com/cordoval/symfony-standard/pull/13/files, i get of course null but it is more because of other reasons and lack of input as to the templates. I found very bad errors on your code @sibok |
Could you please point me the very bad errors? thx |
file_path is non existant is one, but check the diff above i provided and compare to your code. |
Excuses, file_path was an option attribute which works for me due to a File Form Field extension i already made. Anyway, the issue still persists and as said for stof, i'm aware of that issue for about one year at least. I'm closing the issue right now, do someone know if it's going to be fixed? Thx |
$builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event){ $event->getData() is null and it shouldn't be. |
Hi, I have the same problem. |
Hi, I also have the same problem. |
Same problem here |
Not resolved ? Because I have the same problem... . |
Hi, @webmozart I have the same problem.
always return null when in the parent form the collection field have the option 'allow_add' => true, Could you please re open this issue ? |
Hi, I also have the same problem. |
Having the same problem. |
@MConrotte and @nothingaa. The problem is still there if you set the option 'allow_add' => false instead of 'allow_add' => true in the parent collection form field or this change nothing ? |
This is rather annoying to have to disable allow_add as, right now, I have to allow adds. After having given a better insight, I noticed that the child form is called for each item of your collection, plus called the first time without any argument nor data. The quick fix I found is to test if getData() is null or not. Works for me with allow_add => true.
|
Same problem here, thanks @nicolaskern for the tip ! |
Same issue here. Thanks to @nicolaskern as well for the quick fix. |
You're much welcome ;) |
try this maybe: |
Any news about this? I'm having the same problem. |
In my case, the problem is that I want to add field, depending of the value of the getData() instance and the EventListener doesnt allow me to add field to the form. |
Solution found to use POST_SET_DATA, using it, my function to call twice just to do a check for case getData == null not executed See this: |
My situation was that I assumed that a collectionType field which already contains existing objects, can have prototype at the same time (triggered by "allow_add => true"), but in fact that causes the data in PRE_SET_DATA event to be null. |
Related with #5694
Using
$event->getData()
within an event for an embedded form return null.I have tested it for a non-persisted entity with properties assigned in the controller. But it should be the same for persisted entities, I suppose.
The text was updated successfully, but these errors were encountered: