The discussion revolves around limiting topic posting in a category to require selection of a subcategory. rbrlortie explains that while locking the parent category prevents posting altogether, they want to allow posting only when a subcategory is selected. benswift asks if a solution was found. rbrlortie shares a workaround using the Discourse API to modify the post composer, adding validation that checks the number of selected category elements—ensuring at least two (parent and subcategory) are selected before allowing submission, with an error message if not.
This category has a bunch of subcategories. “Robotics”, “Programming”, etc.
So far users can post in “Help & Support”.
Our issue is that nobody is choosing a subcategory.
We would like to limit posting to only those subcategories.
One solution would be to lock the “Help & Support” category. However, we tested this options and since this disable the “New topic” button, people stopped posting there altogether.
Is there a way to keep a category open but configure the minimum depth level of subcategories selected?
Ideally, the current category (“Help & Support”) would be preselected and people would only need to click and select the subcategory.
Does anyone have an idea on how we could achieve this or similar behavior?
We used the API to modify the post composer controller and add error to is. I don’t have the latest version of the code at hand but it was something like this:
In short, this simply looks for the number of elements in the category input and output an error if it’s only one or zero. A subcategory will always have two elements ‘<PARENT><CHILD>’. In this version of the snippet I had laying around, this was done via jQuery. I believe that there was another API call to get the depth of a category.