mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #358 from madmatt/pulls/hide-literalfield-label
ENHANCEMENT: Add 'HideLabel' field for EditableLiteralField objects
This commit is contained in:
commit
881fa401cb
@ -31,7 +31,8 @@ class EditableLiteralField extends EditableFormField {
|
|||||||
|
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
'Content' => 'HTMLText', // From CustomSettings
|
'Content' => 'HTMLText', // From CustomSettings
|
||||||
'HideFromReports' => 'Boolean(0)' // from CustomSettings
|
'HideFromReports' => 'Boolean(0)', // from CustomSettings
|
||||||
|
'HideLabel' => 'Boolean(0)'
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $defaults = array(
|
private static $defaults = array(
|
||||||
@ -103,6 +104,10 @@ class EditableLiteralField extends EditableFormField {
|
|||||||
CheckboxField::create(
|
CheckboxField::create(
|
||||||
'HideFromReports',
|
'HideFromReports',
|
||||||
_t('EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?')
|
_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
|
// Build label and css classes
|
||||||
$label = '';
|
$label = '';
|
||||||
$classes = $this->ExtraClass;
|
$classes = $this->ExtraClass;
|
||||||
if(empty($this->Title)) {
|
if(empty($this->Title) || $this->HideLabel) {
|
||||||
$classes .= " nolabel";
|
$classes .= " nolabel";
|
||||||
} else {
|
} else {
|
||||||
$label = "<label class='left'>{$this->EscapedTitle}</label>";
|
$label = "<label class='left'>{$this->EscapedTitle}</label>";
|
||||||
|
@ -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
|
If you do not check the "Hide from reports" checkbox then this field will be displayed
|
||||||
in submission reports.
|
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
|
Note: Take care not to allow input from unauthorised sources or users, as custom script
|
||||||
or code could be injected into your form.
|
or code could be injected into your form.
|
||||||
|
|
||||||
|
@ -35,4 +35,15 @@ class EditableLiteralFieldTest extends SapphireTest {
|
|||||||
$field->setContent($rawContent);
|
$field->setContent($rawContent);
|
||||||
$this->assertEquals($rawContent, $field->getContent());
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user