Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Form Collection No element by the name of [2] found in form #6585

Closed
ZeinEddin opened this issue Aug 19, 2014 · 23 comments
Closed

Form Collection No element by the name of [2] found in form #6585

ZeinEddin opened this issue Aug 19, 2014 · 23 comments
Assignees
Milestone

Comments

@ZeinEddin
Copy link
Contributor

This line of code $objectData = $this->extract(); introduced in this commit of 2.3.2 https://github.com/zendframework/zf2/pull/6295/files#diff-72ef5001dbc9de4cbafeb235edb1c543R573 caused a problem in my application, I have a form and a fieldset (collection) inside it and when I add new row of the collection using javascript and try to save the form I get the following error:

Additional information:
Zend\Form\Exception\InvalidElementException
File:
vendor/zendframework/zendframework/library/Zend/Form/Fieldset.php:223
Message:
No element by the name of [2] found in form
Stack trace:
#0 vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php(270): Zend\Form\Fieldset->get(2)
#1 vendor/zendframework/zendframework/library/Zend/Form/Fieldset.php(585): Zend\Form\Element\Collection->bindValues(Array)
#2 vendor/zendframework/zendframework/library/Zend/Form/Form.php(364): Zend\Form\Fieldset->bindValues(Array)
#3 vendor/zendframework/zendframework/library/Zend/Form/Form.php(513): Zend\Form\Form->bindValues()
#4 module/PMS/src/PMS/Controller/ClientController.php(188): Zend\Form\Form->isValid()
#5 vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php(83): PMS\Controller\ClientController->editAction()
#6 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#7 vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#8 vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#9 vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#10 vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#11 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#12 vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#13 vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#14 vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(313): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#15 public/index.php(17): Zend\Mvc\Application->run()
#16 {main}

and when I remove the line I mentioned in the beginning everything works fine...

@vixriihi
Copy link
Contributor

Removing $objectData = $this->extract(); would bring back nasty bug that was visible in nested collections.

@vixriihi vixriihi mentioned this issue Aug 29, 2014
@gregorybesson
Copy link

+1 I have the exact same bug :(
@vixriihi seems to have fixed this BC with #6614
No idea when it will be possible to review it and publish the fix ?

Waiting for it, do you have a more elegant solution than fixing the zf2 version to 2.3.1 in my composer ?

@vixriihi
Copy link
Contributor

@gregorybesson If you want to use the version 2.3.2. You could fork zf2 repo at 2.3.2, apply the fix to it and then tell composer to use your patched version instead the original. Details on how to do this can be found here: https://getcomposer.org/doc/05-repositories.md#vcs

@gregorybesson
Copy link

Thanks @vixriihi, I've done it previously but I'll keep waiting for the official release ;)

@thestanislav
Copy link
Contributor

Same bug in my app :(

@jaapio
Copy link
Contributor

jaapio commented Sep 17, 2014

Same issue here. Issue seems to be solved when using a basefieldset in the form.

@Scyks
Copy link

Scyks commented Sep 17, 2014

+1 This following pull request helped solving this issue for me and will also work for 2.3.3
#6614

@Martin-P
Copy link
Contributor

@vixriihi

Removing $objectData = $this->extract(); would bring back nasty bug that was visible in nested collections.

I created a pull request for a different bug (#6711) and removal of $objectData = $this->extract(); does not break any tests. So either the tests do not test what they should test or there is really no problem in removing the line you mentioned.

@vixriihi
Copy link
Contributor

@Martin-P I know that removing the line you referred dons't break any of the existing tests that's why I added two tests in #6614 test "testAddingCollectionElementAfterBind" that fails when No element by the name of [2] found in form error is present and the "testDoesNotCreateNewObjectsWhenUsingNestedCollections" That is the nasty error I was referring before. The last error has been present for a while, but 2.3.2 finally fixed that (maybe by accident, but I really would not like to go back to the workarounds that we had to implement to get a around that bug).

@sebob
Copy link

sebob commented Sep 29, 2014

@Martin-P Couple of days ago i had the same problem, I was looking for code in github and found.
Please look to my repository, maybe can find solution to the problem.
https://github.com/sebob/zf2-fixs/tree/master/library/Zend/Form

@vixriihi
Copy link
Contributor

@sebob that seems to be from the first fix sketch and it would fix the issue also, but you'll also need to change the line to '$data = $this->extract(false);' to pass all the tests. Not sure if there is something else different with the files you linked. I ditched that version because it seemed more elegant to have single purpose methods in this case.

@Martin-P
Copy link
Contributor

IMO the main issue is Zend\Form\Form::extract() doing more than the method name says it does. It does not simply extract (as the method name says), but it also populates. I think the call to populate() should be done elsewhere, because that simply has nothing to do with extraction.

@vixriihi
Copy link
Contributor

Agree with you completely :)

@veewee
Copy link
Contributor

veewee commented Sep 29, 2014

We also have some production issues with this one. Any idea when this will be merged so that the collection component is functional again?

@shofer
Copy link

shofer commented Oct 10, 2014

+1 We have the same problems on adding new elements per Javascript.
The fix of vixriihi seems to work for me.

@SuperDaifuku
Copy link

+1 same here ... hopefully the bugfix gets merged soon

@mungiud
Copy link

mungiud commented Oct 17, 2014

I think this has to do with how you set collection filters

@ins0
Copy link
Contributor

ins0 commented Oct 20, 2014

+1 running into the same bug on my app when adding elements per javascript

@dgram
Copy link

dgram commented Oct 20, 2014

+1 same problem by adding elements via js

@synatix
Copy link

synatix commented Nov 10, 2014

+1 same problem by adding elements via js ....

@PurpleHexagon
Copy link

+1 having the same issue when elements are added via js from template. Would be good for a fix to be merged. vixriihi@da60434 Seems to fix the issue for me

@StyleT
Copy link

StyleT commented Nov 14, 2014

+1 same issue :(

Ocramius pushed a commit that referenced this issue Dec 5, 2014
Ocramius added a commit that referenced this issue Dec 5, 2014
Ocramius added a commit that referenced this issue Dec 5, 2014
Ocramius added a commit that referenced this issue Dec 5, 2014
…g-form-elements' into develop

Close #6585
Close #6614
Forward port #6585
Forward port #6614
@Ocramius
Copy link
Member

Ocramius commented Dec 5, 2014

Handled in #6614

@Ocramius Ocramius added this to the 2.3.4 milestone Dec 5, 2014
@Ocramius Ocramius removed the BC Break label Dec 5, 2014
@Ocramius Ocramius self-assigned this Dec 5, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.