diff options
author | Florrie <towerofnix@gmail.com> | 2018-05-30 23:55:45 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-05-30 23:55:45 -0300 |
commit | 553bbf486e043f206bb8f2c92c943fd688f8fedc (patch) | |
tree | 08366f0c8f9b0624f6b19d4e932fd286a1cab0f1 /ui/form/Form.js | |
parent | f782f7395cd287d4767c1f3ffd20a72a51007595 (diff) |
Un-selectable inputs
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) )) { |