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

Commit f78cf1a

Browse files
committed
Merge branch 'hotfix/122' into develop
Forward port #122 Conflicts: CHANGELOG.md
2 parents c5c718f + 662bf1b commit f78cf1a

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ All notable changes to this project will be documented in this file, in reverse
2020

2121
- Nothing.
2222

23-
## 2.9.2 - TBD
23+
## 2.9.2 - 2016-09-22
2424

2525
### Added
2626

@@ -36,7 +36,11 @@ All notable changes to this project will be documented in this file, in reverse
3636

3737
### Fixed
3838

39-
- Nothing.
39+
- [#122](https://github.com/zendframework/zend-form/pull/122) fixes collection
40+
binding following successful validation. The fix introduced in #106, while it
41+
corrected the behavior around binding a collection that was not re-submitted,
42+
broke behavior around binding submitted collections. #122 corrects the issue,
43+
retaining the fix from #106.
4044

4145
## 2.9.1 - 2016-09-14
4246

src/Fieldset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ public function bindValues(array $values = [], array $validationGroup = null)
570570
foreach ($this->iterator as $element) {
571571
$name = $element->getName();
572572

573-
if ($validationGroup && (array_key_exists($name, $validationGroup) || !in_array($name, $validationGroup))) {
573+
if ($validationGroup && (!array_key_exists($name, $validationGroup) && !in_array($name, $validationGroup))) {
574574
continue;
575575
}
576576

test/FormTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,47 @@ public function testSettingValidationGroupBindsOnlyThoseValuesToModel()
567567
$this->assertObjectNotHasAttribute('foobar', $model);
568568
}
569569

570+
public function testFormWithCollectionAndValidationGroupBindValuesToModel()
571+
{
572+
$model = new stdClass;
573+
$data = [
574+
'foo' => 'abcde',
575+
'categories' => [
576+
[
577+
'name' => 'category'
578+
]
579+
]
580+
];
581+
$this->populateForm();
582+
$this->form->add([
583+
'type' => 'Zend\Form\Element\Collection',
584+
'name' => 'categories',
585+
'options' => [
586+
'count' => 0,
587+
'target_element' => [
588+
'type' => 'ZendTest\Form\TestAsset\CategoryFieldset'
589+
]
590+
]
591+
]);
592+
$this->form->setHydrator(new Hydrator\ObjectProperty());
593+
$this->form->bind($model);
594+
$this->form->setData($data);
595+
$this->form->setValidationGroup([
596+
'foo',
597+
'categories' => [
598+
'name'
599+
]
600+
]);
601+
$this->form->isValid();
602+
603+
$this->assertObjectHasAttribute('foo', $model);
604+
$this->assertEquals('abcde', $model->foo);
605+
$this->assertObjectHasAttribute('categories', $model);
606+
$this->assertObjectHasAttribute('name', $model->categories[0]);
607+
$this->assertEquals('category', $model->categories[0]->getName());
608+
$this->assertObjectNotHasAttribute('foobar', $model);
609+
}
610+
570611
public function testSettingValidationGroupWithoutCollectionBindsOnlyThoseValuesToModel()
571612
{
572613
$model = new stdClass;

0 commit comments

Comments
 (0)