I'm working on a ZF2 application which uses a ZF2 form plus DoctrineModule hydrator to create/update entities in a simple CRUD system. The entity (Union) has a Doctrine OneToMany association with another entitiy (Team), and that association is represented by a Zend\Form\Element\Collection on the form site. Everything works A-OK when creating a new entity or updating an existing entity using the form except for one case: emptying the assocation collection of a pre-existing entity. When I remove all the elements of the collection and click save the form is bounced back and each existing element of the collection shows the error Value is required and can't be empty.
Video showing the issue: http://youtu.be/3ucRb6X61c8
Code:
- Controller: Class, View Scripts
- Service: Class, Factory
- Form: Factory
- Fieldsets:
- Entities:
It seems that the issue boils down to the InputFilter, but I can't seem to pin down exactly what is wrong. Removing up to (N-1) of the N entries of the collection works fine, so it's not a problem with the InputFilter structure itself. Perhaps when the POSTed collection is empty, Zend\Form doesn't remove the existing NotEmpty validator assigned to each element of the teams collection?
A custom input filter is provided (see here) for the Union fieldset, but the teams collection element doesn't have an input listed. I've also tried both removing the custom InputFilter entirely and adding a suitable InputFilter definition for the teams collection, but the end result is the same.
Anyone out there have any insight on what I'm doing wrong here?