8000 Fixed submitting disabled buttons · symfony/symfony@804b2a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 804b2a1

Browse files
committed
Fixed submitting disabled buttons
1 parent 1b92f06 commit 804b2a1

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Symfony/Component/Form/SubmitButton.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public function isClicked()
4343
*/
4444
public function submit($submittedData, $clearMissing = true)
4545
{
46+
if ($this->getConfig()->getDisabled()) {
47+
$this->clicked = false;
48+
49+
return $this;
50+
}
51+
4652
parent::submit($submittedData, $clearMissing);
4753

4854
$this->clicked = null !== $submittedData;

src/Symfony/Component/Form/Tests/CompoundFormTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,28 @@ public function testClickedButtonFromParentForm()
10661066
$this->assertSame($button, $this->form->getClickedButton());
10671067
}
10681068

1069+
public function testDisabledButtonIsNotSubmitted()
1070+
{
1071+
$button = new SubmitButtonBuilder('submit');
1072+
$submit = $button
1073+
->setDisabled(true)
1074+
->getForm();
1075+
1076+
$form = $this->createForm()
1077+
->add($this->getBuilder('text')->getForm())
1078+
->add($submit)
1079+
;
1080+
1081+
$form->submit(array(
1082+
'text' => '',
1083+
'submit' => '',
1084+
));
1085+
1086+
$this->assertTrue($submit->isDisabled());
1087+
$this->assertFalse($submit->isClicked());
1088+
$this->assertFalse($submit->isSubmitted());
1089+
}
1090+
10691091
protected function createForm()
10701092
{
10711093
return $this->getBuilder()

0 commit comments

Comments
 (0)
0