Add support for HTML comments

Fixes #1808
This commit is contained in:
Samuel Georges 2016-02-27 09:46:00 +11:00
parent 77367c4cd9
commit 21f3ac93c1
2 changed files with 18 additions and 10 deletions

View File

@ -262,17 +262,18 @@ class FormField
* Standard config:property values * Standard config:property values
*/ */
$applyConfigValues = [ $applyConfigValues = [
'context', 'commentHtml',
'placeholder', 'placeholder',
'cssClass',
'dependsOn', 'dependsOn',
'required',
'disabled',
'cssClass',
'stretch',
'context',
'hidden',
'trigger', 'trigger',
'preset', 'preset',
'path', 'path',
'required',
'disabled',
'hidden',
'stretch',
]; ];
foreach ($applyConfigValues as $value) { foreach ($applyConfigValues as $value) {
@ -332,11 +333,15 @@ class FormField
* @param bool $isHtml Set to true if you use HTML formatting in the comment * @param bool $isHtml Set to true if you use HTML formatting in the comment
* Supported values are 'below' and 'above' * Supported values are 'below' and 'above'
*/ */
public function comment($text, $position = 'below', $isHtml = false) public function comment($text, $position = 'below', $isHtml = null)
{ {
$this->comment = $text; $this->comment = $text;
$this->commentPosition = $position; $this->commentPosition = $position;
$this->commentHtml = $isHtml;
if ($isHtml !== null) {
$this->commentHtml = $isHtml;
}
return $this; return $this;
} }

View File

@ -5,6 +5,9 @@
<?= $this->renderFieldElement($field) ?> <?= $this->renderFieldElement($field) ?>
<?php else: ?> <?php else: ?>
<?php
$fieldComment = $field->commentHtml ? trans($field->comment) : e(trans($field->comment));
?>
<?php if ($field->label): ?> <?php if ($field->label): ?>
<label for="<?= $field->getId() ?>"> <label for="<?= $field->getId() ?>">
@ -13,13 +16,13 @@
<?php endif ?> <?php endif ?>
<?php if ($field->comment && $field->commentPosition == 'above'): ?> <?php if ($field->comment && $field->commentPosition == 'above'): ?>
<p class="help-block before-field"><?= e(trans($field->comment)) ?></p> <p class="help-block before-field"><?= $fieldComment ?></p>
<?php endif ?> <?php endif ?>
<?= $this->renderFieldElement($field) ?> <?= $this->renderFieldElement($field) ?>
<?php if ($field->comment && $field->commentPosition == 'below'): ?> <?php if ($field->comment && $field->commentPosition == 'below'): ?>
<p class="help-block"><?= e(trans($field->comment)) ?></p> <p class="help-block"><?= $fieldComment ?></p>
<?php endif ?> <?php endif ?>
<?php endif ?> <?php endif ?>