FIX: ensure required_tag_group_name is null if no value present (#14796)

FIX: ensure required_tag_group_name is null if no value present (#14796)

  • FIX: ensure required_tag_group_name is null if no value present

If the array was present but empty required_tag_group_name would be set to undefined, which would then be removed from the payload of the remote request.

Addming the length check ensures the value is set to null, which is sent as an empty value (which the backend sees, and can remove it and persist the change on the Category object).

diff --git a/app/assets/javascripts/discourse/app/models/category.js b/app/assets/javascripts/discourse/app/models/category.js
index c2694e8..17a377e 100644
--- a/app/assets/javascripts/discourse/app/models/category.js
+++ b/app/assets/javascripts/discourse/app/models/category.js
@@ -221,9 +221,10 @@ const Category = RestModel.extend({
             ? this.allowed_tag_groups
             : null,
         allow_global_tags: this.allow_global_tags,
-        required_tag_group_name: this.required_tag_groups
-          ? this.required_tag_groups[0]
-          : null,
+        required_tag_group_name:
+          this.required_tag_groups && this.required_tag_groups.length > 0
+            ? this.required_tag_groups[0]
+            : null,
         min_tags_from_required_group: this.min_tags_from_required_group,
         sort_order: this.sort_order,
         sort_ascending: this.sort_ascending,

GitHub sha: 6360d3d4e7d9a7043848d01f1e9913e4e205a493

This commit appears in #14796 which was approved by eviltrout. It was merged by jbrw.