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
*/
$applyConfigValues = [
'context',
'commentHtml',
'placeholder',
'cssClass',
'dependsOn',
'required',
'disabled',
'cssClass',
'stretch',
'context',
'hidden',
'trigger',
'preset',
'path',
'required',
'disabled',
'hidden',
'stretch',
];
foreach ($applyConfigValues as $value) {
@ -332,11 +333,15 @@ class FormField
* @param bool $isHtml Set to true if you use HTML formatting in the comment
* 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->commentPosition = $position;
$this->commentHtml = $isHtml;
if ($isHtml !== null) {
$this->commentHtml = $isHtml;
}
return $this;
}

View File

@ -5,6 +5,9 @@
<?= $this->renderFieldElement($field) ?>
<?php else: ?>
<?php
$fieldComment = $field->commentHtml ? trans($field->comment) : e(trans($field->comment));
?>
<?php if ($field->label): ?>
<label for="<?= $field->getId() ?>">
@ -13,13 +16,13 @@
<?php endif ?>
<?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 ?>
<?= $this->renderFieldElement($field) ?>
<?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 ?>