The user Canapin is seeking help to move a JavaScript script from a theme to the new JS customization tab in Discourse, aiming to show the tag chooser in the composer only for specific categories. The script, originally based on an old meta post, modifies the composer behavior to conditionally display tags based on category settings. chapoi suggests using CSS to hide the tag field, but renato notes that this won’t prevent non-staff from using tags in other categories unless restricted at the category level. Canapin clarifies that CSS alone won’t work due to the lack of a parent category selector in the composer. david confirms the script should work in the JS tab and offers a modern CSS solution using :has() to hide the tag input except in the desired category. Canapin successfully implements a similar CSS approach with :not() to hide tags except in the ‘Trading Post’ category, concluding the discussion.
For one on my forum, I got rid of this message simply by moving my JS script to the new JS customization tab.
On my other forum, it doesn’t work that easily.
It’s an old override that shows the composer’s tag field only in categories that accept tags:
This script was heavily based on a similar (and old, 2019 or older) modification posted on meta, but I can’t find the original post anymore.
Anyway, there are two questions in one:
How to properly move this in the JS tab? Is it possible, or should I create a theme component?
Is there a more elegant way to hide/show the composer’s tag selector only in certain categories? I use tags for only 1 category on my forum (an ads category with #search and #offer tags)
It doesn’t solve it for staff [1], but if you set the tags as restricted to that category, they won’t be usable (by non-staff) on other categories. From a category /edit/tags:
Tags and tag groups specified above will only be available in this category and other categories that also specify them. They won’t be available for use in other categories.
I had a look at how it works, since it has been a long time.
Tag inputs appear on the composer when creating a new topic regardless of the selected category (even if the category has no available tags for others than admins), which is I want to prevent
CSS only won’t work, because the composer can be open on any page, and there’s no parent CSS targetting the wanted category that would help hiding the composer’s tag input, which I believe is why I used javascript for.
So, unless I’m missing something I still need a script to achieve my goal.
It should be possible to just copy/paste it. Stuff in the JS tab is run in exactly the same way as <script type='text/discourse-plugin>. If it’s not working, can you share the code?