Skip to content

Commit 24de0f3

Browse files
committed
renders correctly Nette\Utils\IHtmlString in data-nette-rules [Closes #243]
1 parent 3e0446c commit 24de0f3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Forms/Helpers.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ public static function exportRules(Rules $rules): array
114114
continue;
115115
}
116116
} else {
117-
$item = ['op' => ($rule->isNegative ? '~' : '') . $op, 'msg' => Validator::formatMessage($rule, false)];
117+
$msg = Validator::formatMessage($rule, false);
118+
if ($msg instanceof Nette\Utils\IHtmlString) {
119+
$msg = html_entity_decode(strip_tags((string) $msg), ENT_QUOTES | ENT_HTML5, 'UTF-8');
120+
}
121+
$item = ['op' => ($rule->isNegative ? '~' : '') . $op, 'msg' => $msg];
118122
}
119123

120124
if (is_array($rule->arg)) {

src/Forms/Validator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ class Validator
4747
];
4848

4949

50-
/** @internal */
50+
/**
51+
* @return string|Nette\Utils\IHtmlString
52+
* @internal
53+
*/
5154
public static function formatMessage(Rule $rule, bool $withValue = true)
5255
{
5356
$message = $rule->message;

0 commit comments

Comments
 (0)