From bf00810e1f5a7164d74ad66f3d03e813d81dfa25 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 8 Jun 2016 12:10:01 +1200 Subject: [PATCH] BUG Fix buttonClicked() error Fixes #3208 --- forms/Form.php | 12 +++++++++--- tests/forms/FormTest.php | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/forms/Form.php b/forms/Form.php index 0714aceef..eac7378a5 100644 --- a/forms/Form.php +++ b/forms/Form.php @@ -873,7 +873,7 @@ class Form extends RequestHandler { /** * Set the target of this form to any value - useful for opening the form contents in a new window or refreshing * another frame - * + * * @param string|FormTemplateHelper */ public function setTemplateHelper($helper) { @@ -1635,11 +1635,17 @@ class Form extends RequestHandler { * @return FormAction */ public function buttonClicked() { - foreach($this->actions->dataFields() as $action) { - if($action->hasMethod('actionname') && $this->buttonClickedFunc == $action->actionName()) { + $actions = $this->actions->dataFields(); + if(!$actions) { + return null; + } + + foreach($actions as $action) { + if($action instanceof FormAction && $this->buttonClickedFunc == $action->actionName()) { return $action; } } + return null; } /** diff --git a/tests/forms/FormTest.php b/tests/forms/FormTest.php index 27814a466..dfcd4fe6e 100644 --- a/tests/forms/FormTest.php +++ b/tests/forms/FormTest.php @@ -19,7 +19,7 @@ class FormTest extends FunctionalTest { Config::inst()->update('Director', 'rules', array( 'FormTest_Controller' => 'FormTest_Controller' )); - + // Suppress themes Config::inst()->remove('SSViewer', 'theme'); } @@ -324,7 +324,7 @@ class FormTest extends FunctionalTest { public function testDisableSecurityTokenAcceptsSubmissionWithoutToken() { SecurityToken::enable(); $expectedToken = SecurityToken::inst()->getValue(); - + $response = $this->get('FormTest_ControllerWithSecurityToken'); // can't use submitForm() as it'll automatically insert SecurityID into the POST data $response = $this->post( @@ -537,6 +537,12 @@ class FormTest extends FunctionalTest { $this->assertEquals('bar', $attrs['foo']); } + public function testButtonClicked() { + $form = $this->getStubForm(); + $action = $form->buttonClicked(); + $this->assertNull($action); + } + public function testAttributesHTML() { $form = $this->getStubForm(); @@ -622,7 +628,7 @@ class FormTest extends FunctionalTest { $formData = $form->getData(); $this->assertEmpty($formData['ExtraFieldCheckbox']); } - + protected function getStubForm() { return new Form( new FormTest_Controller(),