Merge pull request #5665 from tractorcow/pulls/3.3/fix-button-clicked

BUG Fix buttonClicked() error
This commit is contained in:
Daniel Hensby 2016-07-15 00:30:25 +01:00 committed by GitHub
commit a64a066bbf
2 changed files with 18 additions and 6 deletions

View File

@ -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 * Set the target of this form to any value - useful for opening the form contents in a new window or refreshing
* another frame * another frame
* *
* @param string|FormTemplateHelper * @param string|FormTemplateHelper
*/ */
public function setTemplateHelper($helper) { public function setTemplateHelper($helper) {
@ -1635,11 +1635,17 @@ class Form extends RequestHandler {
* @return FormAction * @return FormAction
*/ */
public function buttonClicked() { public function buttonClicked() {
foreach($this->actions->dataFields() as $action) { $actions = $this->actions->dataFields();
if($action->hasMethod('actionname') && $this->buttonClickedFunc == $action->actionName()) { if(!$actions) {
return null;
}
foreach($actions as $action) {
if($action instanceof FormAction && $this->buttonClickedFunc == $action->actionName()) {
return $action; return $action;
} }
} }
return null;
} }
/** /**

View File

@ -19,7 +19,7 @@ class FormTest extends FunctionalTest {
Config::inst()->update('Director', 'rules', array( Config::inst()->update('Director', 'rules', array(
'FormTest_Controller' => 'FormTest_Controller' 'FormTest_Controller' => 'FormTest_Controller'
)); ));
// Suppress themes // Suppress themes
Config::inst()->remove('SSViewer', 'theme'); Config::inst()->remove('SSViewer', 'theme');
} }
@ -324,7 +324,7 @@ class FormTest extends FunctionalTest {
public function testDisableSecurityTokenAcceptsSubmissionWithoutToken() { public function testDisableSecurityTokenAcceptsSubmissionWithoutToken() {
SecurityToken::enable(); SecurityToken::enable();
$expectedToken = SecurityToken::inst()->getValue(); $expectedToken = SecurityToken::inst()->getValue();
$response = $this->get('FormTest_ControllerWithSecurityToken'); $response = $this->get('FormTest_ControllerWithSecurityToken');
// can't use submitForm() as it'll automatically insert SecurityID into the POST data // can't use submitForm() as it'll automatically insert SecurityID into the POST data
$response = $this->post( $response = $this->post(
@ -537,6 +537,12 @@ class FormTest extends FunctionalTest {
$this->assertEquals('bar', $attrs['foo']); $this->assertEquals('bar', $attrs['foo']);
} }
public function testButtonClicked() {
$form = $this->getStubForm();
$action = $form->buttonClicked();
$this->assertNull($action);
}
public function testAttributesHTML() { public function testAttributesHTML() {
$form = $this->getStubForm(); $form = $this->getStubForm();
@ -622,7 +628,7 @@ class FormTest extends FunctionalTest {
$formData = $form->getData(); $formData = $form->getData();
$this->assertEmpty($formData['ExtraFieldCheckbox']); $this->assertEmpty($formData['ExtraFieldCheckbox']);
} }
protected function getStubForm() { protected function getStubForm() {
return new Form( return new Form(
new FormTest_Controller(), new FormTest_Controller(),