diff --git a/src/combo.html b/src/combo.html new file mode 100644 index 0000000..817168a --- /dev/null +++ b/src/combo.html @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/src/combo.js b/src/combo.js new file mode 100644 index 0000000..b451a2d --- /dev/null +++ b/src/combo.js @@ -0,0 +1,38 @@ +import {customElement, inject, bindable, bindingMode} from 'aurelia-framework'; + +@customElement('combo') +@bindable({ + name:'title', + attribute:'title', + defaultBindingMode: bindingMode.oneTime +}) +@bindable({ + name:'options', + attribute:'options', + defaultBindingMode: bindingMode.oneTime +}) +@bindable({ + name:'selected', + attribute:'selected', + defaultBindingMode: bindingMode.twoWay +}) +@inject(Element) +export class Combo { + constructor(element) { + this.element = element; + this._boundChange = this._change.bind(this); + } + + attached() { + this.combo = this.element.querySelector('select'); + this.combo.addEventListener('change', this._boundChange); + } + + detached() { + this.combo.removeEventListener('change', this._boundChange); + } + + _change(change) { + this.selected = change.target.value; + } +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 0578bc1..3a4bddc 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,3 @@ export function configure(aurelia) { - aurelia.globalResources(['lookup-widget','autocomplete-widget']); + aurelia.globalResources(['lookup-widget','autocomplete-widget', 'combo']); } diff --git a/src/lookup-widget.html b/src/lookup-widget.html index 70b027f..8c74db7 100644 --- a/src/lookup-widget.html +++ b/src/lookup-widget.html @@ -1,6 +1,6 @@