dropdown: add sendKey option

This commit is contained in:
jean-emmanuel 2018-02-02 21:27:36 +01:00
parent bce29e7aef
commit 7313090987
3 changed files with 16 additions and 1 deletions

View file

@ -1,5 +1,13 @@
# Changelog
## 0.23.2
- bug fixes
- regression preventing dropdown to display no option selected
- widgets
- switch: wrap non-array `values` property in an array
- dropdown: wrap non-array `values` property in an array; allow setting value by its key/index; add `sendKey` option;
## 0.23.1
- bug fixes

View file

@ -72,6 +72,7 @@ Setting the `push`'s value externally (via osc) will toggle it's inner light.
## Switch
```js
{
type:'switch',
@ -105,3 +106,8 @@ Setting the `push`'s value externally (via osc) will toggle it's inner light.
- usage:
- `array` of possible values to switch between : `[1,2,3]`
- `object` of `"label":value` pairs
### `sendKey`
- type: `boolean`
- default: `false`
- usage: set to `true` to make the dropdown send its selected value's key/index as value. Either way, the dropdown's value can be set using it's value or the associated key/index.

View file

@ -26,6 +26,7 @@ module.exports = class Dropdown extends _widgets_base {
_dropdown:'dropdown',
values:{"Value 1":1,"Value 2":2},
sendKey: false,
value:'',
_osc:'osc',
@ -80,7 +81,7 @@ module.exports = class Dropdown extends _widgets_base {
if (i == -1 && typeof v == 'number' && v >= 0 && v < this.values.length) i = v
if (i != -1) {
this.value = this.values[i]
this.value = this.getProp('sendKey') ? this.keys[i] : this.values[i]
if (!options.fromLocal) this.select.selectedIndex = i
if (options.send) this.sendValue()
if (options.sync) this.changed(options)