forked from MapComplete/MapComplete
Lot's of small improvements
This commit is contained in:
parent
9bd37d9cde
commit
8bca006787
29 changed files with 375 additions and 173 deletions
47
UI/Base/DropDownUI.ts
Normal file
47
UI/Base/DropDownUI.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
import {UIEventSource} from "../UIEventSource";
|
||||
import {UIElement} from "../UIElement";
|
||||
|
||||
export class DropDownUI extends UIElement {
|
||||
|
||||
selectedElement: UIEventSource<string>
|
||||
private _label: string;
|
||||
private _values: { value: string; shown: string }[];
|
||||
|
||||
constructor(label: string, values: { value: string, shown: string }[]) {
|
||||
super(undefined);
|
||||
this._label = label;
|
||||
this._values = values;
|
||||
this.selectedElement = new UIEventSource<string>(values[0].value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected InnerRender(): string {
|
||||
|
||||
let options = "";
|
||||
for (const value of this._values) {
|
||||
options += "<option value='" + value.value + "'>" + value.shown + "</option>"
|
||||
}
|
||||
|
||||
return "<form>" +
|
||||
"<label for='dropdown-" + this.id + "'>" + this._label + "</label>" +
|
||||
"<select name='dropdown-" + this.id + "' id='dropdown-" + this.id + "'>" +
|
||||
options +
|
||||
"</select>" +
|
||||
"</form>";
|
||||
}
|
||||
|
||||
InnerUpdate(htmlElement: HTMLElement) {
|
||||
super.InnerUpdate(htmlElement);
|
||||
|
||||
const self = this;
|
||||
const e = document.getElementById("dropdown-" + this.id);
|
||||
e.onchange = function () {
|
||||
// @ts-ignore
|
||||
const selectedValue = e.options[e.selectedIndex].value;
|
||||
|
||||
self.selectedElement.setData(selectedValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue