Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'fix/validatingCollections' of git://github.com/netiul/z…

…f2 into hotfix/3828
  • Loading branch information...
commit 7b55a36a0371e090ff32e7148c16620019fbe16b 2 parents 2a1c7a8 + 50df7e3
@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.