/
customselect.ts
63 lines (50 loc) · 1.58 KB
/
customselect.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Select, SelectView } from "@bokehjs/models/widgets/selectbox"
import * as p from "@bokehjs/core/properties"
export class CustomSelectView extends SelectView {
override model: CustomSelect
connect_signals(): void {
super.connect_signals()
this.connect(this.model.properties.disabled_options.change, () => this._update_disabled_options())
}
protected options_el(): HTMLOptionElement[] | HTMLOptGroupElement[] {
let opts = super.options_el()
opts.forEach((element) => {
if (this.model.disabled_options.includes(element.value)) {
element.setAttribute('disabled', 'true')
}
})
return opts
}
protected _update_disabled_options(): void {
for (const element of this.input_el.options) {
if (this.model.disabled_options.includes(element.value)) {
element.setAttribute('disabled', 'true')
} else {
element.removeAttribute('disabled')
}
}
}
}
export namespace CustomSelect {
export type Attrs = p.AttrsOf<Props>
export type Props = Select.Props & {
disabled_options: p.Property<string[]>
}
}
export interface CustomSelect extends CustomSelect.Attrs {}
export class CustomSelect extends Select {
override properties: CustomSelect.Props
override __view_type__: CustomSelectView
constructor(attrs?: Partial<CustomSelect.Attrs>) {
super(attrs)
}
static __module__ = "panel.models.widgets"
static {
this.prototype.default_view = CustomSelectView
this.define<CustomSelect.Props>(({Array, String}) => {
return {
disabled_options: [ Array(String), [] ],
}
})
}
}