BUG FormAction title property cannot be set if useButtonTag is false

This commit is contained in:
Damian Mooyman 2019-10-29 17:19:22 +13:00
parent c7597ad265
commit e76601e5c8
No known key found for this signature in database
GPG Key ID: 19B1752E86A700BB
2 changed files with 24 additions and 6 deletions

View File

@ -184,15 +184,20 @@ class FormAction extends FormField
public function getAttributes()
{
return array_merge(
$attributes = array_merge(
parent::getAttributes(),
array(
[
'disabled' => ($this->isReadonly() || $this->isDisabled()),
'value' => $this->Title(),
'type' => $this->getInputType(),
'title' => ($this->useButtonTag) ? $this->description : null,
)
'value' => $this->Title(),
'type' => $this->getInputType(),
]
);
// Override title with description if supplied
if ($this->getDescription()) {
$attributes['title'] = $this->getDescription();
}
return $attributes;
}
/**

View File

@ -16,4 +16,17 @@ class FormActionTest extends SapphireTest
$formAction->setAttribute('src', 'file.png');
$this->assertContains('type="image"', $formAction->getAttributesHTML());
}
public function testGetTitle()
{
// Test that description overrides title attribute, but doesn't prevent it from
// working if blank.
$action = new FormAction('test');
$action->setAttribute('title', 'this is the title');
$this->assertEquals('this is the title', $action->getAttribute('title'));
$action->setDescription('this is a better title');
$this->assertEquals('this is a better title', $action->getAttribute('title'));
$action->setDescription(null);
$this->assertEquals('this is the title', $action->getAttribute('title'));
}
}