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

Commit

Permalink
Merge branch 'hotfix/3828' into develop
Browse files Browse the repository at this point in the history
Forward port #3828
  • Loading branch information
weierophinney committed Feb 20, 2013
2 parents d5a82f2 + a3bff21 commit ab2eb77
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
6 changes: 2 additions & 4 deletions library/Zend/Form/Form.php
Expand Up @@ -558,10 +558,8 @@ protected function prepareValidationGroup(FieldsetInterface $formOrFieldset, arr
$values = array();

if (isset($data[$key])) {
$count = count($data[$key]);

for ($i = 0; $i != $count; ++$i) {
$values[] = $value;
foreach(array_keys($data[$key]) as $cKey) {
$values[$cKey] = $value;
}
}

Expand Down
32 changes: 32 additions & 0 deletions tests/ZendTest/Form/FormTest.php
Expand Up @@ -1124,6 +1124,38 @@ public function testApplyObjectInputFilterToBaseFieldsetAndApplyValidationGroup(
$this->assertTrue($this->form->isValid());
}

public function testFormValidationCanHandleNonConsecutiveKeysOfCollectionInData()
{
$dataWithCollection = array(
'foo' => 'bar',
'categories' => array(
0 => array('name' => 'cat1'),
1 => array('name' => 'cat2'),
3 => array('name' => 'cat3'),
),
);
$this->populateForm();
$this->form->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'categories',
'options' => array(
'count' => 1,
'allow_add' => true,
'target_element' => array(
'type' => 'ZendTest\Form\TestAsset\CategoryFieldset'
)
)
));
$this->form->setValidationGroup(array(
'foo',
'categories' => array(
'name'
)
));
$this->form->setData($dataWithCollection);
$this->assertTrue($this->form->isValid());
}

public function testAddNonBaseFieldsetObjectInputFilterToFormInputFilter()
{
$fieldset = new Fieldset('foobar');
Expand Down

0 comments on commit ab2eb77

Please sign in to comment.