« get me outta code hell

tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
path: root/ui/controls/Form.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/controls/Form.js')
-rw-r--r--ui/controls/Form.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/ui/controls/Form.js b/ui/controls/Form.js
index 921096a..0224247 100644
--- a/ui/controls/Form.js
+++ b/ui/controls/Form.js
@@ -81,8 +81,10 @@ export default class Form extends FocusElement {
   }
 
   previousInput() {
-    // TODO: Forms currently assume there is at least one selectable input,
-    // but this isn't necessarily always the case.
+    if (this.inputs.length === 0) {
+      return
+    }
+
     do {
       this.curIndex = (this.curIndex - 1)
       if (this.curIndex < 0) {
@@ -94,7 +96,10 @@ export default class Form extends FocusElement {
   }
 
   nextInput() {
-    // TODO: See previousInput
+    if (this.inputs.length === 0) {
+      return
+    }
+
     do {
       this.curIndex = (this.curIndex + 1) % this.inputs.length
     } while (!this.inputs[this.curIndex].selectable)
@@ -103,9 +108,12 @@ export default class Form extends FocusElement {
   }
 
   firstInput(selectForm = true) {
+    if (this.inputs.length === 0) {
+      return
+    }
+
     this.curIndex = 0
 
-    // TODO: See previousInput
     if (!this.inputs[this.curIndex].selectable) {
       this.nextInput()
     }
@@ -118,9 +126,12 @@ export default class Form extends FocusElement {
   }
 
   lastInput(selectForm = true) {
+    if (this.inputs.length === 0) {
+      return
+    }
+
     this.curIndex = this.inputs.length - 1
 
-    // TODO: See previousInput
     if (!this.inputs[this.curIndex].selectable) {
       this.previousInput()
     }