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

Commit

Permalink
Merge branch 'hotfix/2779'
Browse files Browse the repository at this point in the history
Close #2779
  • Loading branch information
weierophinney committed Oct 16, 2012
2 parents fd52f74 + e4dd7ba commit beade08
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
10 changes: 8 additions & 2 deletions library/Zend/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ public function bindValues(array $values = array())
if (!is_object($this->object)) {
return;
}
if (!$this->isValid) {
if (!$this->hasValidated() && !empty($values)) {
$this->setData($values);
if (!$this->isValid()) {
return;
}
} elseif (!$this->isValid) {
return;
}

Expand Down Expand Up @@ -434,6 +439,8 @@ public function isValid()
}

$this->isValid = $result = $filter->isValid();
$this->hasValidated = true;

if ($result && $this->bindOnValidate()) {
$this->bindValues();
}
Expand All @@ -442,7 +449,6 @@ public function isValid()
$this->setMessages($filter->getMessages());
}

$this->hasValidated = true;
return $result;
}

Expand Down
29 changes: 29 additions & 0 deletions tests/ZendTest/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,35 @@ public function testCanAddFieldsetsUsingSpecs()
$this->assertEquals('my.form.fieldset', $fieldset->getAttribute('data-js-type'));
}

public function testFormAsFieldsetWillBindValuesToObject()
{
$parentForm = new Form('parent');
$parentFormObject = new \ArrayObject(array('parentId' => null));
$parentFormElement = new Element('parentId');
$parentForm->setObject($parentFormObject);
$parentForm->add($parentFormElement);

$childForm = new Form('child');
$childFormObject = new \ArrayObject(array('childId' => null));
$childFormElement = new Element('childId');
$childForm->setObject($childFormObject);
$childForm->add($childFormElement);

$parentForm->add($childForm);

$data = array(
'parentId' => 'mpinkston was here',
'child' => array(
'childId' => 'testing 123'
)
);

$parentForm->setData($data);
$this->assertTrue($parentForm->isValid());
$this->assertEquals($data['parentId'], $parentFormObject['parentId']);
$this->assertEquals($data['child']['childId'], $childFormObject['childId']);
}

public function testWillUseInputSpecificationFromElementInInputFilterIfNoMatchingInputFound()
{
$element = new TestAsset\ElementWithFilter('foo');
Expand Down

0 comments on commit beade08

Please sign in to comment.