Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow forms that have been added as fieldsets to bind values to bound ob... #2779

Closed
wants to merge 1 commit into from

2 participants

Matt Pinkston Matthew Weier O'Phinney
Matt Pinkston

...jects.

Currently, forms that are added as fieldsets to other forms will not bind values to bound objects because they never get a chance to validate. This checks to see if the form has not been validated and if values are being passed. If so, it sets the data, validates, and continues binding the values to the bound object.

Matthew Weier O'Phinney weierophinney referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney [#2779] CS fixes
- elseif
488d37b
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney [#2779] CS fixes
- elseif
e4dd7ba
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/2779'
Close #2779
beade08
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/2779' into develop
Forward port #2779
36bf718
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 37 additions and 2 deletions.
  1. +8 −2 library/Zend/Form/Form.php
  2. +29 −0 tests/ZendTest/Form/FormTest.php
10 library/Zend/Form/Form.php
View
@@ -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;
+ }
+ } else if (!$this->isValid) {
return;
}
@@ -434,6 +439,8 @@ public function isValid()
}
$this->isValid = $result = $filter->isValid();
+ $this->hasValidated = true;
+
if ($result && $this->bindOnValidate()) {
$this->bindValues();
}
@@ -442,7 +449,6 @@ public function isValid()
$this->setMessages($filter->getMessages());
}
- $this->hasValidated = true;
return $result;
}
29 tests/ZendTest/Form/FormTest.php
View
@@ -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');
Something went wrong with that request. Please try again.