Merge pull request #358 from madmatt/pulls/hide-literalfield-label

ENHANCEMENT: Add 'HideLabel' field for EditableLiteralField objects
This commit is contained in:
Damian Mooyman 2015-10-22 10:15:56 +13:00
commit 881fa401cb
3 changed files with 22 additions and 2 deletions

View File

@ -31,7 +31,8 @@ class EditableLiteralField extends EditableFormField {
private static $db = array(
'Content' => 'HTMLText', // From CustomSettings
'HideFromReports' => 'Boolean(0)' // from CustomSettings
'HideFromReports' => 'Boolean(0)', // from CustomSettings
'HideLabel' => 'Boolean(0)'
);
private static $defaults = array(
@ -103,6 +104,10 @@ class EditableLiteralField extends EditableFormField {
CheckboxField::create(
'HideFromReports',
_t('EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?')
),
CheckboxField::create(
'HideLabel',
_t('EditableLiteralField.HIDELABEL', "Hide 'Title' label on frontend?")
)
));
@ -113,7 +118,7 @@ class EditableLiteralField extends EditableFormField {
// Build label and css classes
$label = '';
$classes = $this->ExtraClass;
if(empty($this->Title)) {
if(empty($this->Title) || $this->HideLabel) {
$classes .= " nolabel";
} else {
$label = "<label class='left'>{$this->EscapedTitle}</label>";

View File

@ -132,6 +132,10 @@ You can edit the HTML blog from the "Show options" link.
If you do not check the "Hide from reports" checkbox then this field will be displayed
in submission reports.
If you check the "Hide 'Title' label on frontend" checkbox then the title of this field
will be hidden on the form. This is useful when you want to output specific HTML code and
add your own headings within the content of this field.
Note: Take care not to allow input from unauthorised sources or users, as custom script
or code could be injected into your form.

View File

@ -35,4 +35,15 @@ class EditableLiteralFieldTest extends SapphireTest {
$field->setContent($rawContent);
$this->assertEquals($rawContent, $field->getContent());
}
public function testHideLabel() {
$field = new EditableLiteralField(array(
'Title' => 'Test label'
));
$this->assertContains('Test label', $field->getFormField()->Field());
$field->HideLabel = true;
$this->assertNotContains('Test label', $field->getFormField()->Field());
}
}