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

Commit

Permalink
Apply defaults to collection fieldsets too
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwindell committed Apr 15, 2013
1 parent 2d0f6d0 commit 7ee6bf3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions library/Zend/Form/Element/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,19 @@ public function getTargetElement()
return $this->targetElement;
}

/**
* {@inheritdoc}
*
* If the target element is a FieldsetInterface, return it's attached elements
*/
public function getElements()
{
if ($this->getTargetElement() instanceof FieldsetInterface) {
return $this->getTargetElement()->getElements();
}
return parent::getElements();
}

/**
* Get allow add
*
Expand Down
6 changes: 6 additions & 0 deletions tests/ZendTest/Form/Element/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,10 @@ protected function prepareForExtract($collection)
'obj3' => $obj3,
));
}

public function testGetElementsForFieldsetCollectionReturnsFieldsetElements()
{
$collection = $this->form->get('fieldsets');
$this->assertCount(1, $collection->getElements());
}
}
2 changes: 1 addition & 1 deletion tests/ZendTest/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ public function testDonNotApplyEmptyInputFiltersToSubFieldsetOfCollectionElement
$this->form->setInputFilter($inputFilter);

$this->assertInstanceOf('Zend\InputFilter\CollectionInputFilter', $this->form->getInputFilter()->get('items'));
$this->assertCount(0, $this->form->getInputFilter()->get('items')->getInputs());
$this->assertCount(1, $this->form->getInputFilter()->get('items')->getInputs());
}

public function testFormValidationCanHandleNonConsecutiveKeysOfCollectionInData()
Expand Down

0 comments on commit 7ee6bf3

Please sign in to comment.