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

Commit

Permalink
Merge branch 'feature/162' into develop
Browse files Browse the repository at this point in the history
Close #162
  • Loading branch information
weierophinney committed Dec 6, 2017
2 parents a3dc303 + 22839d6 commit 54484b0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ All notable changes to this project will be documented in this file, in reverse
for the `FormElementErrors` view helper to translate validation error messages
using the composed translator and text domain instances.

### Changed

- Nothing.

### Deprecated

- Nothing.
Expand All @@ -20,7 +24,10 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#162](https://github.com/zendframework/zend-form/pull/162) fixes an issue
with hydration when a form has called `setWrapElements(true)`, ensuring that
binding values in a fieldset will correctly identify the elements in the
provided data.

## 2.10.3 - TBD

Expand Down
4 changes: 1 addition & 3 deletions src/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,7 @@ public function bindValues(array $values = [], array $validationGroup = null)
$hydrator = $this->getHydrator();
$hydratableData = [];

foreach ($this->iterator as $element) {
$name = $element->getName();

foreach ($this->iterator as $name => $element) {
if ($validationGroup
&& (! array_key_exists($name, $validationGroup) && ! in_array($name, $validationGroup))
) {
Expand Down
33 changes: 33 additions & 0 deletions test/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,39 @@ public function testCallingBindValuesWhenBindOnValidateIsDisabledPopulatesBoundO
], $model->foobar);
}

public function testBindValuesWithWrappingPopulatesBoundObject()
{
$model = new stdClass;
$validSet = [
'foo' => 'abcde',
'bar' => ' ALWAYS valid ',
'foobar' => [
'foo' => 'abcde',
'bar' => ' always VALID',
],
];
$this->populateForm();
$this->form->setHydrator(new Hydrator\ObjectProperty());
$this->form->setName('formName');
$this->form->setWrapElements(true);
$this->form->prepare();
$this->form->bind($model);
$this->form->setData($validSet);

$this->assertObjectNotHasAttribute('foo', $model);
$this->assertObjectNotHasAttribute('bar', $model);
$this->assertObjectNotHasAttribute('foobar', $model);

$this->form->isValid();

$this->assertEquals($validSet['foo'], $model->foo);
$this->assertEquals('always valid', $model->bar);
$this->assertEquals([
'foo' => 'abcde',
'bar' => 'always valid',
], $model->foobar);
}

public function testHasFactoryComposedByDefault()
{
$factory = $this->form->getFormFactory();
Expand Down

0 comments on commit 54484b0

Please sign in to comment.