Skip to content

A platform for community discussion. Free, open, simple.

DEV: Allow html entities in field titles (#37295)

Penar Musaraj2709d366f3ec
diff --git a/frontend/discourse/app/form-kit/components/fk/field-data.gjs b/frontend/discourse/app/form-kit/components/fk/field-data.gjs
index 2819e171818..5b4543e6304 100644
--- a/frontend/discourse/app/form-kit/components/fk/field-data.gjs
+++ b/frontend/discourse/app/form-kit/components/fk/field-data.gjs
@@ -35,7 +35,7 @@ export default class FKFieldData extends Component {
constructor() {
super(...arguments);
- if (!this.args.title?.length) {
+ if (!this.args.title?.toString?.()?.length) {
throw new Error("@title is required on `<form.Field />`.");
}
}
diff --git a/frontend/discourse/tests/integration/components/form-kit/field-test.gjs b/frontend/discourse/tests/integration/components/form-kit/field-test.gjs
index afe03b6766c..0d4213bc7de 100644
--- a/frontend/discourse/tests/integration/components/form-kit/field-test.gjs
+++ b/frontend/discourse/tests/integration/components/form-kit/field-test.gjs
@@ -1,4 +1,5 @@
import { fn, hash } from "@ember/helper";
+import { htmlSafe } from "@ember/template";
import {
click,
fillIn,
@@ -126,6 +127,25 @@ module("Integration | Component | FormKit | Field", function (hooks) {
resetOnerror();
});
+ test("@title with htmlSafe", async function (assert) {
+ const htmlTitle = htmlSafe('Title with <a href="#">link</a>');
+
+ await render(
+ <template>
+ <Form as |form|>
+ <form.Field @name="foo" @title={{htmlTitle}} as |field|>
+ <field.Checkbox />
+ </form.Field>
+ </Form>
+ </template>
+ );
+
+ assert
+ .dom(".form-kit__control-checkbox-title a")
+ .exists("it renders HTML in the title");
+ assert.dom(".form-kit__control-checkbox-title a").hasAttribute("href", "#");
+ });
+
test("@validation", async function (assert) {
await render(
<template>