Browse Source

Add check to see if input is empty

nztqa 8 years ago
parent
commit
29f65be1e0
2 changed files with 16 additions and 9 deletions
  1. 1 1
      client/components/cards/checklists.jade
  2. 15 8
      client/components/cards/checklists.js

+ 1 - 1
client/components/cards/checklists.jade

@@ -4,7 +4,7 @@ template(name="checklists")
     each checklist in currentCard.checklists
       +checklistDetail(checklist = checklist)
   if canModifyCard
-    +inlinedForm(classNames="js-add-checklist" cardId = cardId)
+    +inlinedForm(autoclose=false classNames="js-add-checklist" cardId = cardId)
       +addChecklistItemForm
     else
       a.js-open-inlined-form

+ 15 - 8
client/components/cards/checklists.js

@@ -4,13 +4,18 @@ BlazeComponent.extendComponent({
     const textarea = this.find('textarea.js-add-checklist-item');
     const title = textarea.value.trim();
     const cardId = this.currentData().cardId;
-    Checklists.insert({
-      cardId,
-      title,
-    });
-    setTimeout(() => {
-      this.$('.add-checklist-item').last().click();
-    }, 100);
+
+    if (title) {
+      Checklists.insert({
+        cardId,
+        title,
+      });
+      setTimeout(() => {
+        this.$('.add-checklist-item').last().click();
+      }, 100);
+    }
+    textarea.value = '';
+    textarea.focus();
   },
 
   addChecklistItem(event) {
@@ -18,8 +23,10 @@ BlazeComponent.extendComponent({
     const textarea = this.find('textarea.js-add-checklist-item');
     const title = textarea.value.trim();
     const checklist = this.currentData().checklist;
-    checklist.addItem(title);
 
+    if (title) {
+      checklist.addItem(title);
+    }
     // We keep the form opened, empty it.
     textarea.value = '';
     textarea.focus();