diff options
Diffstat (limited to 'ui/form/Form.js')
-rw-r--r-- | ui/form/Form.js | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/ui/form/Form.js b/ui/form/Form.js index ce064aa..e5d756a 100644 --- a/ui/form/Form.js +++ b/ui/form/Form.js @@ -59,6 +59,10 @@ module.exports = class Form extends FocusElement { } } + get selectable() { + return this.inputs.some(inp => inp.selectable) + } + updateSelectedElement() { if (this.root.select) { this.root.select(this.inputs[this.curIndex]) @@ -66,16 +70,23 @@ module.exports = class Form extends FocusElement { } previousInput() { - this.curIndex = (this.curIndex - 1) - if (this.curIndex < 0) { - this.curIndex = (this.inputs.length - 1) - } + // TODO: Forms currently assume there is at least one selectable input, + // but this isn't necessarily always the case. + do { + this.curIndex = (this.curIndex - 1) + if (this.curIndex < 0) { + this.curIndex = (this.inputs.length - 1) + } + } while (!this.inputs[this.curIndex].selectable) this.updateSelectedElement() } nextInput() { - this.curIndex = (this.curIndex + 1) % this.inputs.length + // TODO: See previousInput + do { + this.curIndex = (this.curIndex + 1) % this.inputs.length + } while (!this.inputs[this.curIndex].selectable) this.updateSelectedElement() } @@ -83,6 +94,11 @@ module.exports = class Form extends FocusElement { firstInput(selectForm = true) { this.curIndex = 0 + // TODO: See previousInput + if (!this.inputs[this.curIndex].selectable) { + this.nextInput() + } + if (selectForm || ( this.root.isChildOrSelfSelected && this.root.isChildOrSelfSelected(this) )) { |