/
selecteditor.ts
43 lines (36 loc) · 1.25 KB
/
selecteditor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Decorators } from "../../types/decorators";
import { ComboboxItem } from "./combobox";
import { ComboboxCommonOptions, ComboboxEditor } from "./comboboxeditor";
import { EditorProps } from "./editorwidget";
@Decorators.registerClass('Serenity.SelectEditor')
export class SelectEditor<P extends SelectEditorOptions = SelectEditorOptions> extends ComboboxEditor<P, ComboboxItem> {
constructor(props: EditorProps<P>) {
super(props);
this.updateItems();
}
getItems() {
return this.options.items || [];
}
protected emptyItemText() {
if (this.options.emptyOptionText) {
return this.options.emptyOptionText;
}
return super.emptyItemText();
}
updateItems() {
var items = this.getItems();
this.clearItems();
if (items.length > 0) {
var isStrings = typeof (items[0]) === 'string';
for (var item of items) {
var key = isStrings ? item : item[0];
var text = isStrings ? item : (item[1] ?? item[0]);
this.addOption(key, text, item, false);
}
}
}
}
export interface SelectEditorOptions extends ComboboxCommonOptions {
items?: any[];
emptyOptionText?: string;
}