bug #25927 [Form] Fixed submitting disabled buttons (HeahDude)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form] Fixed submitting disabled buttons

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23759
| License       | MIT
| Doc PR        | ~

Commits
-------

804b2a1a47 Fixed submitting disabled buttons
This commit is contained in:
Fabien Potencier 2018-01-26 08:31:44 +01:00
commit 0cd675ca4a
2 changed files with 28 additions and 0 deletions

View File

@ -43,6 +43,12 @@ class SubmitButton extends Button implements ClickableInterface
*/
public function submit($submittedData, $clearMissing = true)
{
if ($this->getConfig()->getDisabled()) {
$this->clicked = false;
return $this;
}
parent::submit($submittedData, $clearMissing);
$this->clicked = null !== $submittedData;

View File

@ -1066,6 +1066,28 @@ class CompoundFormTest extends AbstractFormTest
$this->assertSame($button, $this->form->getClickedButton());
}
public function testDisabledButtonIsNotSubmitted()
{
$button = new SubmitButtonBuilder('submit');
$submit = $button
->setDisabled(true)
->getForm();
$form = $this->createForm()
->add($this->getBuilder('text')->getForm())
->add($submit)
;
$form->submit(array(
'text' => '',
'submit' => '',
));
$this->assertTrue($submit->isDisabled());
$this->assertFalse($submit->isClicked());
$this->assertFalse($submit->isSubmitted());
}
protected function createForm()
{
return $this->getBuilder()