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

Fixed: Form/Element/Collection can't remove all elements #7447

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions library/Zend/Form/Element/Collection.php
Expand Up @@ -195,11 +195,6 @@ public function populateValues($data)
));
}

// Can't do anything with empty data
if (empty($data)) {
return;
}

if (!$this->allowRemove && count($data) < $this->count) {
throw new Exception\DomainException(sprintf(
'There are fewer elements than specified in the collection (%s). Either set the allow_remove option '
Expand Down
11 changes: 8 additions & 3 deletions tests/ZendTest/Form/Element/CollectionTest.php
Expand Up @@ -939,14 +939,19 @@ public function testCanRemoveAllElementsIfAllowRemoveIsTrue()
$collection->setAllowRemove(true);
$collection->setCount(0);


// By default, $collection contains 2 elements
$data = array();
$data[] = 'blue';
$data[] = 'green';

$collection->populateValues($data);
$this->assertEquals(2, count($collection->getElements()));

$collection->populateValues(array());
$this->assertEquals(0, count($collection->getElements()));
}


public function testCanBindObjectMultipleNestedFieldsets()
{
$productFieldset = new ProductFieldset();
Expand Down Expand Up @@ -1234,14 +1239,14 @@ public function testCollectionShouldSilentlyIgnorePopulatingFieldsetWithDisallow
public function testCanHydrateObject()
{
$form = $this->form;
$object = new \ArrayObject();
$form->bind($object);
$data = array(
'colors' => array(
'#ffffff',
),
);
$form->setData($data);
$object = new \ArrayObject();
$form->bind($object);
$this->assertTrue($form->isValid());
$this->assertTrue(is_array($object['colors']));
$this->assertCount(1, $object['colors']);
Expand Down