From be0919ac31b1048248941ed0c290c03824732297 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 3 May 2020 14:57:01 -0300 Subject: fix long-ignored crash interacting with empty form --- ui/form/Form.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'ui/form/Form.js') diff --git a/ui/form/Form.js b/ui/form/Form.js index 451baa4..f61c7b6 100644 --- a/ui/form/Form.js +++ b/ui/form/Form.js @@ -81,8 +81,10 @@ module.exports = 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 @@ module.exports = 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 @@ module.exports = 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 @@ module.exports = 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() } -- cgit 1.3.0-6-gf8a5