diff --git a/CHANGELOG.md b/CHANGELOG.md index 4445b4aa..cc493575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - widgets - keyboard: make `on` and `off` properties dynamic - script: add `getIndex` function + - matrix/keyboard: `id` variable in script is now the `id` of the child widget that triggered the event ## 1.6.0 diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index a551d3a1..118d73d9 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -17,6 +17,9 @@ Depending on what triggered the script's execution, a few variables are availabl - `value`: widget's value - `touch`: see [Touch state](#touch-state) +??? infos "Keyboard & Matrix" + In keyboards and matrices, `id` is the id of the child widget that triggered the event. + **Event: keyboard** (script widget only) - `type` (`string`): `keydown` or `keyup` diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index df7a7a77..3b39b9c9 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -216,7 +216,9 @@ class Widget extends EventEmitter { event: 'value' }, builtIn: true, parent: this}) this.on('change', (e)=>{ - if (e.widget === this && this.mounted && !e.options.fromEdit) this.script.setValue(this.value, {...e.options, id: e.options.id || e.id}) + if (e.widget === this && this.mounted && !e.options.fromEdit) { + this.script.setValue(e.options.widget ? e.options.widget.value : this.value, {...e.options, id: e.options.id || e.id}) + } }) if (String(this.getProp('script')).includes('touch')) { this.on('touch', (e)=>{ diff --git a/src/client/widgets/containers/keyboard.js b/src/client/widgets/containers/keyboard.js index a117b93b..b80fa8b1 100644 --- a/src/client/widgets/containers/keyboard.js +++ b/src/client/widgets/containers/keyboard.js @@ -51,21 +51,27 @@ class Keyboard extends Panel { this.childrenType = undefined this.value = [] - + this.on('change',(e)=>{ - if (e.widget === this) return + var widget = e.widget - this.value[e.widget._index] = e.widget.getValue() + if (widget === this) return + + this.value[widget._index] = widget.getValue() if (e.options.send) { var start = parseInt(this.getProp('start')) this.sendValue({ - v: [e.widget._index + start, e.widget.getValue() ? this.getProp('on') : this.getProp('off')] + v: [e.widget._index + start, widget.getValue() ? this.getProp('on') : this.getProp('off')] }) } - this.changed(e.options) + this.changed({ + ...e.options, + id: widget.getProp('id') + }) + }) diff --git a/src/client/widgets/containers/matrix.js b/src/client/widgets/containers/matrix.js index b505c693..e2f12132 100644 --- a/src/client/widgets/containers/matrix.js +++ b/src/client/widgets/containers/matrix.js @@ -44,22 +44,16 @@ class Matrix extends Panel { if (e.widget === this) return - if (this.getProp('widgetType') === 'clone') { + var widget = this.getProp('widgetType') === 'clone' ? e.widget.parent : e.widget - if (e.widget.parent.parent !== this) return + if (widget.parent !== this) return - this.value[e.widget.parent._index] = e.widget.getValue() + this.value[widget._index] = e.widget.getValue() - } else { - - if (e.widget.parent !== this) return - - this.value[e.widget._index] = e.widget.getValue() - - - } - - this.changed(e.options) + this.changed({ + ...e.options, + id: widget.getProp('id') + }) })