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

Commit

Permalink
Merge pull request #122 from rwrz/hotfix/121
Browse files Browse the repository at this point in the history
fix #106 PR problem (bug #121)
  • Loading branch information
weierophinney committed Sep 22, 2016
2 parents c0a62f9 + 7f2e1ab commit 1411a9d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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 1411a9d

Please sign in to comment.