Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'hotfix/3828' into develop

Forward port #3828
  • Loading branch information...
commit ab2eb77a4c232648f7644e18db1415e0340c248e 2 parents d5a82f2 + a3bff21
@weierophinney weierophinney authored
Showing with 34 additions and 4 deletions.
  1. +2 −4 library/Zend/Form/Form.php
  2. +32 −0 tests/ZendTest/Form/FormTest.php
View
6 library/Zend/Form/Form.php
@@ -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;
}
}
View
32 tests/ZendTest/Form/FormTest.php
@@ -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');
Please sign in to comment.
Something went wrong with that request. Please try again.