الحد الأدنى لمستوى القسم / الفئة الفرعية للنشر في موضوع

Hi,

  • We have a category called “Help & Support”.

  • 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?

Thanks,
R.

مرحبًا، هل تمكنت من معرفة كيفية فعل ذلك؟

استخدمنا الـ API لتعديل وحدة تحكم محرر المنشور وإضافة خطأ إليها. لا أملك أحدث إصدار من الكود بين يدي، لكنه كان شبيهاً بهذا:

var computed = require("ember-addons/ember-computed-decorators").default;
api.modifyClass('controller:composer',
    {
      save(opts) {
        var categoryNb = $('.category-input .category-chooser .selected-name > span').length;
        if((categoryNb !== 0 && categoryNb < 2)  ) {
            this.set("lastValidatedAt", Date.now());
            return false;
        }
        return this._super(opts);
      },
      @computed("model.categoryId", "lastValidatedAt")
      categoryValidation(categoryId, lastValidatedAt) {
          var InputValidation = require("discourse/models/input-validation").default;
          var categoryNb = $('.category-input .category-chooser .selected-name > span').length;
          if( (categoryNb !== 0 && categoryNb < 2)  ) {
              return InputValidation.create({
                  failed: true,
                  reason: 'You need to select a subcategory',
                  lastShownAt: lastValidatedAt
                });
          } else {
              return this._super(categoryId, lastValidatedAt);
          }
      }
  }
);

باختصار، يبحث هذا الكود ببساطة في عدد العناصر في إدخال الفئة، ويُصدر خطأً إذا كان العدد واحداً أو صفراً. فالفئة الفرعية ستحتوي دائماً على عنصرين ‘<PARENT><CHILD>’. في هذا الإصدار من المقطع الذي كان معي، تم ذلك عبر مكتبة jQuery. وأعتقد أن هناك استدعاءً آخر للـ API للحصول على عمق الفئة.