diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 2631faf618..e22415c95e 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -505,27 +505,10 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac // they are collectable during submission only $this->errors = []; - $dispatcher = $this->config->getEventDispatcher(); - // Obviously, a disabled form should not change its data upon submission. - if ($this->isDisabled() && $this->isRoot()) { + if ($this->isDisabled()) { $this->submitted = true; - if ($dispatcher->hasListeners(FormEvents::PRE_SUBMIT)) { - $event = new FormEvent($this, $submittedData); - $dispatcher->dispatch(FormEvents::PRE_SUBMIT, $event); - } - - if ($dispatcher->hasListeners(FormEvents::SUBMIT)) { - $event = new FormEvent($this, $this->getNormData()); - $dispatcher->dispatch(FormEvents::SUBMIT, $event); - } - - if ($dispatcher->hasListeners(FormEvents::POST_SUBMIT)) { - $event = new FormEvent($this, $this->getViewData()); - $dispatcher->dispatch(FormEvents::POST_SUBMIT, $event); - } - return $this; } @@ -555,6 +538,8 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac $this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.'); } + $dispatcher = $this->config->getEventDispatcher(); + $modelData = null; $normData = null; $viewData = null; @@ -767,6 +752,10 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac throw new LogicException('Cannot check if an unsubmitted form is valid. Call Form::isSubmitted() before Form::isValid().'); } + if ($this->isDisabled()) { + return true; + } + return 0 === \count($this->getErrors(true)); } diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index e44eaf5ae4..c655de4a13 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -55,7 +55,7 @@ class CompoundFormTest extends AbstractFormTest $this->assertFalse($this->form->isValid()); } - public function testDisabledFormsInvalidEvenChildrenInvalid() + public function testDisabledFormsValidEvenIfChildrenInvalid() { $form = $this->getBuilder('person') ->setDisabled(true) @@ -68,7 +68,7 @@ class CompoundFormTest extends AbstractFormTest $form->get('name')->addError(new FormError('Invalid')); - $this->assertFalse($form->isValid()); + $this->assertTrue($form->isValid()); } public function testSubmitForwardsNullIfNotClearMissingButValueIsExplicitlyNull()