Awesome, this worked really well!
Here is the snippet for the composer window’s categoryValidation override, if anyone stumble here using the search.
<script type="text/discourse-plugin" version="0.8.23">
const computed = require("ember-addons/ember-computed-decorators").default;
api.modifyClass('controller:composer', {
@computed("model.categoryId", "lastValidatedAt")
categoryValidation(categoryId, lastValidatedAt) {
var InputValidation = require("discourse/models/input-validation").default;
var categoryDepth = /*Find categoryId's category level*/;
if(this.get('model').draftKey == "new_topic" && (categoryDepth !== 0 && categoryDepth < 2)) {
return InputValidation.create({
failed: true,
reason: 'You need to select a subcategory',
lastShownAt: lastValidatedAt
}); //THIS WORKS AND DISPLAY AN CUSTOM ERROR MESSAGE
} else {
return this._super(categoryId, lastValidatedAt);
}
}
});
</script>