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

Commit

Permalink
Merge branch 'hotfix/122'
Browse files Browse the repository at this point in the history
Close #122
Fixes #121
  • Loading branch information
weierophinney committed Sep 22, 2016
2 parents c0a62f9 + 662bf1b commit 0023be0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.9.2 - TBD
## 2.9.2 - 2016-09-22

### Added

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

### Fixed

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

## 2.9.1 - 2016-09-14

Expand Down
2 changes: 1 addition & 1 deletion src/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ public function bindValues(array $values = [], array $validationGroup = null)
foreach ($this->iterator as $element) {
$name = $element->getName();

if ($validationGroup && (array_key_exists($name, $validationGroup) || !in_array($name, $validationGroup))) {
if ($validationGroup && (!array_key_exists($name, $validationGroup) && !in_array($name, $validationGroup))) {
continue;
}

Expand Down
41 changes: 41 additions & 0 deletions test/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,47 @@ public function testSettingValidationGroupBindsOnlyThoseValuesToModel()
$this->assertObjectNotHasAttribute('foobar', $model);
}

public function testFormWithCollectionAndValidationGroupBindValuesToModel()
{
$model = new stdClass;
$data = [
'foo' => 'abcde',
'categories' => [
[
'name' => 'category'
]
]
];
$this->populateForm();
$this->form->add([
'type' => 'Zend\Form\Element\Collection',
'name' => 'categories',
'options' => [
'count' => 0,
'target_element' => [
'type' => 'ZendTest\Form\TestAsset\CategoryFieldset'
]
]
]);
$this->form->setHydrator(new Hydrator\ObjectProperty());
$this->form->bind($model);
$this->form->setData($data);
$this->form->setValidationGroup([
'foo',
'categories' => [
'name'
]
]);
$this->form->isValid();

$this->assertObjectHasAttribute('foo', $model);
$this->assertEquals('abcde', $model->foo);
$this->assertObjectHasAttribute('categories', $model);
$this->assertObjectHasAttribute('name', $model->categories[0]);
$this->assertEquals('category', $model->categories[0]->getName());
$this->assertObjectNotHasAttribute('foobar', $model);
}

public function testSettingValidationGroupWithoutCollectionBindsOnlyThoseValuesToModel()
{
$model = new stdClass;
Expand Down

0 comments on commit 0023be0

Please sign in to comment.