Niveau minimum de département de catégorie/sous-catégorie pour publier un sujet

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.

Salut, as-tu trouvé comment faire ça ?

Nous avons utilisé l’API pour modifier le contrôleur du compositeur de messages et y ajouter une validation d’erreur. Je n’ai pas la dernière version du code sous la main, mais cela ressemblait à ceci :

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: 'Vous devez sélectionner une sous-catégorie',
                  lastShownAt: lastValidatedAt
                });
          } else {
              return this._super(categoryId, lastValidatedAt);
          }
      }
  }
);

En résumé, cela vérifie simplement le nombre d’éléments dans le champ de sélection de catégorie et renvoie une erreur s’il n’y en a qu’un ou zéro. Une sous-catégorie aura toujours deux éléments ‘’. Dans cette version du fragment que j’avais sous la main, cela était fait via jQuery. Je pense qu’il y avait un autre appel API pour obtenir la profondeur d’une catégorie.