A platform for community discussion. Free, open, simple.
FEAT: category-specific topic title placeholder (#38593)
Bannon Tannerc29e72280157
diff --git a/app/assets/stylesheets/common/base/edit-category.scss b/app/assets/stylesheets/common/base/edit-category.scssindex 98f095497e6..e12768063cd 100644--- a/app/assets/stylesheets/common/base/edit-category.scss+++ b/app/assets/stylesheets/common/base/edit-category.scss@@ -230,7 +230,8 @@ div.edit-category {}.edit-category-tab-settings,- .edit-category-tab-tags {+ .edit-category-tab-tags,+ .edit-category-tab-topic-template {> section {margin-bottom: 1.5em;}diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rbindex fae8db12f5e..e73bcbc7d6a 100644--- a/app/controllers/categories_controller.rb+++ b/app/controllers/categories_controller.rb@@ -622,6 +622,7 @@ class CategoriesController < ApplicationController:slug,:allow_badges,:topic_template,+ :topic_title_placeholder,:description,:sort_order,:sort_ascending,diff --git a/app/models/category.rb b/app/models/category.rbindex a239a9be238..bc22b0fdcd1 100644--- a/app/models/category.rb+++ b/app/models/category.rb@@ -1272,64 +1272,65 @@ end# Table name: categories## id :integer not null, primary key-# name :string(50) not null-# color :string(6) default("0088CC"), not null-# topic_id :integer-# topic_count :integer default(0), not null-# created_at :datetime not null-# updated_at :datetime not null-# user_id :integer not null-# topics_year :integer default(0)-# topics_month :integer default(0)-# topics_week :integer default(0)-# slug :string not null-# description :text-# text_color :string(6) default("FFFFFF"), not null-# read_restricted :boolean default(FALSE), not null-# auto_close_hours :float-# post_count :integer default(0), not null-# latest_post_id :integer-# latest_topic_id :integer-# position :integer-# parent_category_id :integer-# posts_year :integer default(0)-# posts_month :integer default(0)-# posts_week :integer default(0)-# email_in :string-# email_in_allow_strangers :boolean default(FALSE)-# topics_day :integer default(0)-# posts_day :integer default(0)+# all_topics_wiki :boolean default(FALSE), not null# allow_badges :boolean default(TRUE), not null-# name_lower :string(50) not null+# allow_global_tags :boolean default(FALSE), not null+# allow_unlimited_owner_edits_on_first_post :boolean default(FALSE), not null# auto_close_based_on_last_post :boolean default(FALSE)-# topic_template :text+# auto_close_hours :float+# color :string(6) default("0088CC"), not null# contains_messages :boolean-# sort_order :string-# sort_ascending :boolean-# uploaded_logo_id :integer-# uploaded_background_id :integer-# topic_featured_link_allowed :boolean default(TRUE)-# all_topics_wiki :boolean default(FALSE), not null-# show_subcategory_list :boolean default(FALSE)-# num_featured_topics :integer default(3)-# default_view :string(50)-# subcategory_list_style :string(50) default("rows_with_featured_topics")+# default_list_filter :string(20) default("all")+# default_slow_mode_seconds :integer# default_top_period :string(20) default("all")+# default_view :string(50)+# description :text+# email_in :string+# email_in_allow_strangers :boolean default(FALSE)+# emoji :string+# icon :string+# locale :string(20)# mailinglist_mirror :boolean default(FALSE), not null# minimum_required_tags :integer default(0), not null+# name :string(50) not null+# name_lower :string(50) not null# navigate_to_first_post_after_read :boolean default(FALSE), not null-# search_priority :integer default(0)-# allow_global_tags :boolean default(FALSE), not null+# num_featured_topics :integer default(3)+# position :integer+# post_count :integer default(0), not null+# posts_day :integer default(0)+# posts_month :integer default(0)+# posts_week :integer default(0)+# posts_year :integer default(0)# read_only_banner :string-# default_list_filter :string(20) default("all")-# allow_unlimited_owner_edits_on_first_post :boolean default(FALSE), not null-# default_slow_mode_seconds :integer-# uploaded_logo_dark_id :integer-# uploaded_background_dark_id :integer+# read_restricted :boolean default(FALSE), not null+# search_priority :integer default(0)+# show_subcategory_list :boolean default(FALSE)+# slug :string not null+# sort_ascending :boolean+# sort_order :string# style_type :integer default("square"), not null-# emoji :string-# icon :string-# locale :string(20)+# subcategory_list_style :string(50) default("rows_with_featured_topics")+# text_color :string(6) default("FFFFFF"), not null+# topic_count :integer default(0), not null+# topic_featured_link_allowed :boolean default(TRUE)+# topic_template :text+# topic_title_placeholder :string+# topics_day :integer default(0)+# topics_month :integer default(0)+# topics_week :integer default(0)+# topics_year :integer default(0)+# created_at :datetime not null+# updated_at :datetime not null+# latest_post_id :integer+# latest_topic_id :integer+# parent_category_id :integer+# topic_id :integer+# uploaded_background_dark_id :integer+# uploaded_background_id :integer+# uploaded_logo_dark_id :integer+# uploaded_logo_id :integer+# user_id :integer not null## Indexes#diff --git a/app/serializers/basic_category_serializer.rb b/app/serializers/basic_category_serializer.rbindex 646f36a39bf..592953f3119 100644--- a/app/serializers/basic_category_serializer.rb+++ b/app/serializers/basic_category_serializer.rb@@ -23,6 +23,7 @@ class BasicCategorySerializer < ApplicationSerializer:notification_level,:can_edit,:topic_template,+ :topic_title_placeholder,:has_children,:subcategory_count,:sort_order,diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex b02b01f51a5..47a99728d05 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -4649,6 +4649,8 @@ en:advanced: "Advanced"show_advanced: "Advanced settings"topic_template: "Template"+ topic_title_placeholder: "Category topic title placeholder"+ topic_title_placeholder_placeholder: "[optional] custom topic title placeholder for this category"tags: "Tags"localizations: "Localizations"localization:diff --git a/db/migrate/20260306183220_add_topic_title_placeholder_to_categories.rb b/db/migrate/20260306183220_add_topic_title_placeholder_to_categories.rbnew file mode 100644index 00000000000..d45d2835f69--- /dev/null+++ b/db/migrate/20260306183220_add_topic_title_placeholder_to_categories.rb@@ -0,0 +1,7 @@+# frozen_string_literal: true++class AddTopicTitlePlaceholderToCategories < ActiveRecord::Migration[8.0]+ def change+ add_column :categories, :topic_title_placeholder, :string, null: true+ end+enddiff --git a/frontend/discourse/admin/controllers/edit-category/tabs.js b/frontend/discourse/admin/controllers/edit-category/tabs.jsindex 55eb715f659..a9676d50ba3 100644--- a/frontend/discourse/admin/controllers/edit-category/tabs.js+++ b/frontend/discourse/admin/controllers/edit-category/tabs.js@@ -30,6 +30,7 @@ const LEGACY_FORMKIT_FIELDS = ["email_in_allow_strangers","mailinglist_mirror","topic_template",+ "topic_title_placeholder","form_template_ids",];@@ -75,6 +76,7 @@ const SIMPLIFIED_FIELD_LIST = ["allow_global_tags","default_slow_mode_seconds","topic_template",+ "topic_title_placeholder","form_template_ids","uploaded_logo","uploaded_logo_dark",diff --git a/frontend/discourse/app/components/category-topic-template-editor.gjs b/frontend/discourse/app/components/category-topic-template-editor.gjsindex 0cb76d523b7..2f8bf090954 100644--- a/frontend/discourse/app/components/category-topic-template-editor.gjs+++ b/frontend/discourse/app/components/category-topic-template-editor.gjs@@ -6,6 +6,7 @@ import { LinkTo } from "@ember/routing";import { service } from "@ember/service";import DEditor from "discourse/components/d-editor";import DToggleSwitch from "discourse/components/d-toggle-switch";+import TextField from "discourse/components/text-field";import FormTemplateChooser from "discourse/select-kit/components/form-template-chooser";import { i18n } from "discourse-i18n";@@ -15,6 +16,7 @@ export default class CategoryTopicTemplateEditor extends Component {@tracked _showFormTemplateOverride;@tracked _localTopicTemplate;+ @tracked _localTopicTitlePlaceholder;get topicTemplate() {return this._localTopicTemplate ?? this.args.category?.topic_template;@@ -24,6 +26,17 @@ export default class CategoryTopicTemplateEditor extends Component {this._localTopicTemplate = value;}+ get topicTitlePlaceholder() {+ return (+ this._localTopicTitlePlaceholder ??+ this.args.category?.topic_title_placeholder+ );+ }++ set topicTitlePlaceholder(value) {+ this._localTopicTitlePlaceholder = value;+ }+get showInsertLinkButton() {if (this.args.showInsertLinkButton === undefined) {return true;@@ -75,6 +88,17 @@ export default class CategoryTopicTemplateEditor extends Component {}}+ @action+ handleTopicTitlePlaceholderChange(event) {+ const value = event.target.value;+ this.topicTitlePlaceholder = value;+ if (this.args.onChange) {+ this.args.onChange("topic_title_placeholder", value);+ } else {+ this.args.category.set("topic_title_placeholder", value);+ }+ }+@actionhandleTopicTemplateChange(event) {const value = event.target.value;@@ -87,6 +111,17 @@ export default class CategoryTopicTemplateEditor extends Component {}<template>+ <div class="control-group">+ <label for="category-topic-title-placeholder">+ {{i18n "category.topic_title_placeholder"}}+ </label>+ <TextField+ @value={{this.topicTitlePlaceholder}}+ @id="category-topic-title-placeholder"+ @placeholderKey="category.topic_title_placeholder_placeholder"+ @change={{this.handleTopicTitlePlaceholderChange}}+ />+ </div>{{#if this.siteSettings.enable_form_templates}}<div class="control-group"><DToggleSwitchdiff --git a/frontend/discourse/app/components/composer-title.gjs b/frontend/discourse/app/components/composer-title.gjsindex 8402dfded65..79c7da17873 100644--- a/frontend/discourse/app/components/composer-title.gjs+++ b/frontend/discourse/app/components/composer-title.gjs@@ -227,6 +227,14 @@ export default class ComposerTitle extends Component {);}+ @computed("composer.categoryTitlePlaceholder", "composer.titlePlaceholder")+ get titleAriaLabel() {+ return (+ this.composer.categoryTitlePlaceholder ||+ i18n(this.composer.titlePlaceholder)+ );+ }+bodyIsDefault() {const reply = this.get("composer.reply") || "";return (@@ -241,7 +249,8 @@ export default class ComposerTitle extends Component {@id="reply-title"@maxLength={{this.titleMaxLength}}@placeholderKey={{this.composer.titlePlaceholder}}- @aria-label={{i18n this.composer.titlePlaceholder}}+ @placeholder={{this.composer.categoryTitlePlaceholder}}+ @aria-label={{this.titleAriaLabel}}@disabled={{this.disabled}}@autocomplete="off"/>diff --git a/frontend/discourse/app/models/category.js b/frontend/discourse/app/models/category.jsindex 790f8709c3f..0f83610530b 100644--- a/frontend/discourse/app/models/category.js+++ b/frontend/discourse/app/models/category.js@@ -804,6 +804,7 @@ export default class Category extends RestModel {category_setting_attributes: this.category_setting,custom_fields: this.custom_fields,topic_template: this.topic_template,+ topic_title_placeholder: this.topic_title_placeholder,form_template_ids: this.form_template_ids,all_topics_wiki: this.all_topics_wiki,allow_unlimited_owner_edits_on_first_post:diff --git a/frontend/discourse/app/models/composer.js b/frontend/discourse/app/models/composer.jsindex ab47de357db..965f33cc384 100644--- a/frontend/discourse/app/models/composer.js+++ b/frontend/discourse/app/models/composer.js@@ -450,6 +450,11 @@ export default class Composer extends RestModel {: "composer.title_placeholder";}+ @computed("category.topic_title_placeholder")+ get categoryTitlePlaceholder() {+ return this.category?.topic_title_placeholder || null;+ }+@computed("action", "post", "topic", "topic.title")get replyOptions() {const options = {diff --git a/frontend/discourse/tests/acceptance/edit-category-topic-template-test.js b/frontend/discourse/tests/acceptance/edit-category-topic-template-test.jsindex 950284e771f..9dfa014c322 100644--- a/frontend/discourse/tests/acceptance/edit-category-topic-template-test.js+++ b/frontend/discourse/tests/acceptance/edit-category-topic-template-test.js@@ -71,6 +71,25 @@ acceptance();});+ test("Changing topic title placeholder saves correctly", async function (assert) {+ putData = null;+ await visit("/c/bug/edit/topic-template");++ await fillIn("#category-topic-title-placeholder", "Enter a bug title");++ assert+ .dom(".admin-changes-banner")+ .exists("banner is shown after changing topic title placeholder");++ await click(".admin-changes-banner .btn-primary");++ assert.strictEqual(+ putData.topic_title_placeholder,+ "Enter a bug title",+ "it sends the updated topic title placeholder"+ );+ });+test("Selecting a form template shows the unsaved changes banner", async function (assert) {putData = null;await visit("/c/bug/edit/topic-template");@@ -116,6 +135,7 @@ acceptance("Admin - Legacy edit category topic template", function (needs) {slug: "bug",can_edit: true,topic_template: "Existing template content",+ topic_title_placeholder: "Existing placeholder",category_type_site_settings: {},permissions: [],},@@ -158,4 +178,26 @@ acceptance("Admin - Legacy edit category topic template", function (needs) {"it sends the updated topic template in legacy flow");});++ test("Changing topic title placeholder saves correctly", async function (assert) {+ putData = null;+ await visit("/c/bug/edit/topic-template");++ assert+ .dom("#category-topic-title-placeholder")+ .hasValue(+ "Existing placeholder",+ "it loads the existing topic title placeholder"+ );++ await fillIn("#category-topic-title-placeholder", "Legacy placeholder");++ await click("#save-category");++ assert.strictEqual(+ putData.topic_title_placeholder,+ "Legacy placeholder",+ "it sends the updated topic title placeholder in legacy flow"+ );+ });});diff --git a/spec/requests/api/schemas/json/category_create_response.json b/spec/requests/api/schemas/json/category_create_response.jsonindex e8b48972ace..ae840596e2a 100644--- a/spec/requests/api/schemas/json/category_create_response.json+++ b/spec/requests/api/schemas/json/category_create_response.json@@ -89,6 +89,12 @@"null"]},+ "topic_title_placeholder": {+ "type": [+ "string",+ "null"+ ]+ },"form_template_ids": {"type": "array","items": {}@@ -342,6 +348,7 @@"notification_level","can_edit","topic_template",+ "topic_title_placeholder","has_children","subcategory_count","sort_order",diff --git a/spec/requests/api/schemas/json/category_list_response.json b/spec/requests/api/schemas/json/category_list_response.jsonindex 08495969ec8..cd811fbcdc9 100644--- a/spec/requests/api/schemas/json/category_list_response.json+++ b/spec/requests/api/schemas/json/category_list_response.json@@ -84,6 +84,12 @@"null"]},+ "topic_title_placeholder": {+ "type": [+ "string",+ "null"+ ]+ },"has_children": {"type": "boolean"},@@ -211,6 +217,7 @@"notification_level","can_edit","topic_template",+ "topic_title_placeholder","has_children","subcategory_count","sort_order",diff --git a/spec/requests/api/schemas/json/category_update_response.json b/spec/requests/api/schemas/json/category_update_response.jsonindex 069885b00a5..610f67225cb 100644--- a/spec/requests/api/schemas/json/category_update_response.json+++ b/spec/requests/api/schemas/json/category_update_response.json@@ -92,6 +92,12 @@"null"]},+ "topic_title_placeholder": {+ "type": [+ "string",+ "null"+ ]+ },"form_template_ids": {"type": "array","items": {}@@ -342,6 +348,7 @@"notification_level","can_edit","topic_template",+ "topic_title_placeholder","form_template_ids","has_children","subcategory_count",diff --git a/spec/requests/api/schemas/json/site_response.json b/spec/requests/api/schemas/json/site_response.jsonindex 863ecf6a9a9..a168b498fc7 100644--- a/spec/requests/api/schemas/json/site_response.json+++ b/spec/requests/api/schemas/json/site_response.json@@ -708,6 +708,12 @@"null"]},+ "topic_title_placeholder": {+ "type": [+ "string",+ "null"+ ]+ },"has_children": {"type": "boolean"},@@ -853,6 +859,7 @@"permission","notification_level","topic_template",+ "topic_title_placeholder","has_children","subcategory_count","sort_order",diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rbindex 273f7dcaf7b..6c4efe4b80e 100644--- a/spec/requests/categories_controller_spec.rb+++ b/spec/requests/categories_controller_spec.rb@@ -934,6 +934,7 @@ RSpec.describe CategoriesController doallow_global_tags: "true",required_tag_groups: [{ name: tag_group.name, min_count: 2 }],form_template_ids: [form_template_1.id, form_template_2.id],+ topic_title_placeholder: "test topic title placeholder",}expect(response.status).to eq(200)@@ -956,6 +957,7 @@ RSpec.describe CategoriesController doexpect(category.category_required_tag_groups.first.tag_group.id).to eq(tag_group.id)expect(category.category_required_tag_groups.first.min_count).to eq(2)expect(category.form_template_ids).to eq([form_template_1.id, form_template_2.id])+ expect(category.topic_title_placeholder).to eq("test topic title placeholder")endit "logs the changes correctly" dodiff --git a/spec/system/composer/category_templates_spec.rb b/spec/system/composer/category_templates_spec.rbindex 81ceceb1179..e4768b09992 100644--- a/spec/system/composer/category_templates_spec.rb+++ b/spec/system/composer/category_templates_spec.rb@@ -633,4 +633,26 @@ describe "Composer Form Templates", type: :system doexpect(mini_tag_chooser).to have_no_selectionendend++ context "when a category has a topic title placeholder" do+ fab!(:category_with_title_placeholder) do+ Fabricate(:category, topic_title_placeholder: "Describe your issue briefly")+ end++ it "shows custom topic title placeholder in the composer" do+ category_page.visit(category_with_title_placeholder)+ category_page.new_topic_button.click++ expect(page).to have_field("reply-title", placeholder: "Describe your issue briefly")+ end++ it "falls back to default placeholder if category topic title placeholder is nil" do+ SiteSetting.topic_featured_link_enabled = false+ category_with_title_placeholder.update!(topic_title_placeholder: nil)+ category_page.visit(category_with_title_placeholder)+ category_page.new_topic_button.click++ expect(find("#reply-title")[:placeholder]).to eq(I18n.t("js.composer.title_placeholder"))+ end+ endenddiff --git a/spec/system/edit_category_topic_template_spec.rb b/spec/system/edit_category_topic_template_spec.rbnew file mode 100644index 00000000000..0213afc82ce--- /dev/null+++ b/spec/system/edit_category_topic_template_spec.rb@@ -0,0 +1,16 @@+# frozen_string_literal: true++describe "Edit category topic template", type: :system do+ fab!(:admin)+ fab!(:category)++ before { sign_in admin }++ it "saves and displays a custom topic title placeholder" do+ visit "/c/#{category.slug}/edit/topic-template"+ find("#category-topic-title-placeholder").fill_in(with: "Describe your issue briefly")+ find("#save-category").click++ expect(category.reload.topic_title_placeholder).to eq("Describe your issue briefly")+ end+end