FIX: 1.length is undefined, prefer isPresent

FIX: 1.length is undefined, prefer isPresent

diff --git a/assets/javascripts/discourse/controllers/policy-builder.js.es6 b/assets/javascripts/discourse/controllers/policy-builder.js.es6
index 41baedd..f17f57f 100644
--- a/assets/javascripts/discourse/controllers/policy-builder.js.es6
+++ b/assets/javascripts/discourse/controllers/policy-builder.js.es6
@@ -1,3 +1,4 @@
+import { isPresent } from "@ember/utils";
 import I18n from "I18n";
 import TextLib from "discourse/lib/text";
 import ModalFunctionality from "discourse/mixins/modal-functionality";
@@ -80,7 +81,7 @@ export default Controller.extend(ModalFunctionality, {
     Object.keys(form).forEach((key) => {
       const value = form[key];
 
-      if (value && value.length) {
+      if (value && isPresent(value)) {
         markdownParams.push(`${key}="${value}"`);
       }
     });
@@ -100,12 +101,12 @@ export default Controller.extend(ModalFunctionality, {
   },
 
   _validateForm(form) {
-    if (!form.group || !form.group.length) {
+    if (!form.group || !isPresent(form.group)) {
       this.flash(I18n.t("discourse_policy.builder.errors.group"), "error");
       return false;
     }
 
-    if (!form.version || !form.version.length) {
+    if (!form.version || !isPresent(form.version)) {
       this.flash(I18n.t("discourse_policy.builder.errors.version"), "error");
       return false;
     }

GitHub sha: 45ce75c8

1 Like