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

Commit 54484b0

Browse files
committed
Merge branch 'feature/162' into develop
Close #162
2 parents a3dc303 + 22839d6 commit 54484b0

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ All notable changes to this project will be documented in this file, in reverse
1010
for the `FormElementErrors` view helper to translate validation error messages
1111
using the composed translator and text domain instances.
1212

13+
### Changed
14+
15+
- Nothing.
16+
1317
### Deprecated
1418

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

2125
### Fixed
2226

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

2532
## 2.10.3 - TBD
2633

src/Fieldset.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,7 @@ public function bindValues(array $values = [], array $validationGroup = null)
569569
$hydrator = $this->getHydrator();
570570
$hydratableData = [];
571571

572-
foreach ($this->iterator as $element) {
573-
$name = $element->getName();
574-
572+
foreach ($this->iterator as $name => $element) {
575573
if ($validationGroup
576574
&& (! array_key_exists($name, $validationGroup) && ! in_array($name, $validationGroup))
577575
) {

test/FormTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,39 @@ public function testCallingBindValuesWhenBindOnValidateIsDisabledPopulatesBoundO
785785
], $model->foobar);
786786
}
787787

788+
public function testBindValuesWithWrappingPopulatesBoundObject()
789+
{
790+
$model = new stdClass;
791+
$validSet = [
792+
'foo' => 'abcde',
793+
'bar' => ' ALWAYS valid ',
794+
'foobar' => [
795+
'foo' => 'abcde',
796+
'bar' => ' always VALID',
797+
],
798+
];
799+
$this->populateForm();
800+
$this->form->setHydrator(new Hydrator\ObjectProperty());
801+
$this->form->setName('formName');
802+
$this->form->setWrapElements(true);
803+
$this->form->prepare();
804+
$this->form->bind($model);
805+
$this->form->setData($validSet);
806+
807+
$this->assertObjectNotHasAttribute('foo', $model);
808+
$this->assertObjectNotHasAttribute('bar', $model);
809+
$this->assertObjectNotHasAttribute('foobar', $model);
810+
811+
$this->form->isValid();
812+
813+
$this->assertEquals($validSet['foo'], $model->foo);
814+
$this->assertEquals('always valid', $model->bar);
815+
$this->assertEquals([
816+
'foo' => 'abcde',
817+
'bar' => 'always valid',
818+
], $model->foobar);
819+
}
820+
788821
public function testHasFactoryComposedByDefault()
789822
{
790823
$factory = $this->form->getFormFactory();

0 commit comments

Comments
 (0)